[python] PY-35730 use NonAsciiCharactersInspection to report non-ascii characters in python regular expressions

(cherry picked from commit d80469c6b698863b8986a7c9486fb7e69c418fcf)

GitOrigin-RevId: 2400ea51b7b3b3d72011195ca336e4cf69d17931
This commit is contained in:
Morgan Bartholomew
2025-11-12 10:47:17 +00:00
committed by intellij-monorepo-bot
parent 4067221a8f
commit a453fede94
7 changed files with 105 additions and 7 deletions
@@ -289,6 +289,24 @@ public class PyRegexpTest extends PyTestCase {
);
}
@TestFor(issues="PY-35730")
public void testGroupNameIsValidIdentifier() {
//noinspection NonAsciiCharacters
testHighlighting(
"""
import re
re.compile("(?P<水>水)") # non-ascii is a valid group name, a warning will be reported by `NonAsciiCharactersInspection`
re.compile("(?P<𝕏>水)") # ok character outside the BMP
# broken case IJPL-217664
# re.compile("(?Perror descr="Invalid group name">😀</error>>水)") # bad character outside the BMP
re.compile("(?P<<error descr="Group name expected"> </error>a>水)")
re.compile("(?P<<error descr="Group name expected">0</error>a>水)")
re.compile("(?P<<error descr="Invalid group name">a$b</error>>水)")
""");
}
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {