From 2a559ec31a2e66cbc2a78f697eb79cee5c4a9500 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Tue, 23 Jul 2019 18:26:17 +0300 Subject: [PATCH] Don't mark named unicode character as an error in Python 3.8+ (PY-36004) GitOrigin-RevId: 59b52a42e5c820a6603e6734e768f035c5c593e5 --- .../psi/impl/PyStringLiteralExpressionImpl.java | 11 +++++++++++ python/testData/highlighting/namedUnicode.py | 3 +++ python/testData/highlighting/namedUnicodeBefore38.py | 3 +++ .../com/jetbrains/python/PythonHighlightingTest.java | 10 ++++++++++ 4 files changed, 27 insertions(+) create mode 100644 python/testData/highlighting/namedUnicode.py create mode 100644 python/testData/highlighting/namedUnicodeBefore38.py diff --git a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java index 620ec3090653..59478edaa4dd 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionImpl.java @@ -40,6 +40,7 @@ import com.jetbrains.python.psi.types.TypeEvalContext; import one.util.streamex.StreamEx; import org.intellij.lang.regexp.DefaultRegExpPropertiesProvider; import org.intellij.lang.regexp.RegExpLanguageHost; +import org.intellij.lang.regexp.UnicodeCharacterNames; import org.intellij.lang.regexp.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -422,4 +423,14 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt public String[][] getKnownCharacterClasses() { return myPropertiesProvider.getKnownCharacterClasses(); } + + @Override + public boolean supportsNamedCharacters(RegExpNamedCharacter namedCharacter) { + return LanguageLevel.forElement(this).isAtLeast(LanguageLevel.PYTHON38); + } + + @Override + public boolean isValidNamedCharacter(RegExpNamedCharacter namedCharacter) { + return UnicodeCharacterNames.getCodePoint(namedCharacter.getName()) >= 0; + } } diff --git a/python/testData/highlighting/namedUnicode.py b/python/testData/highlighting/namedUnicode.py new file mode 100644 index 000000000000..e0085f668085 --- /dev/null +++ b/python/testData/highlighting/namedUnicode.py @@ -0,0 +1,3 @@ +import re +re.match(r'\N{LESS-THAN SIGN}', '<') +re.match(r'\N{LESS-THAN SIG}', '<') \ No newline at end of file diff --git a/python/testData/highlighting/namedUnicodeBefore38.py b/python/testData/highlighting/namedUnicodeBefore38.py new file mode 100644 index 000000000000..28fc38afca48 --- /dev/null +++ b/python/testData/highlighting/namedUnicodeBefore38.py @@ -0,0 +1,3 @@ +import re +re.match(r'\N{LESS-THAN SIGN}', '<') +re.match(r'\N{LESS-THAN SIG}', '<') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java index 44ad702fd36f..0b052a9b9dc1 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -436,6 +436,16 @@ public class PythonHighlightingTest extends PyTestCase { doTest(LanguageLevel.PYTHON37, false, false); } + // PY-36004 + public void testNamedUnicodeBefore38() { + doTest(LanguageLevel.PYTHON37, false, false); + } + + // PY-36004 + public void testNamedUnicode() { + doTest(LanguageLevel.PYTHON38, false, false); + } + @NotNull private static EditorColorsScheme createTemporaryColorScheme() { EditorColorsManager manager = EditorColorsManager.getInstance();