Skip to content

Commit 5df5286

Browse files
fangyi-zhouserhiy-storchaka
authored andcommitted
bpo-30688: Import unicodedata only when needed. (GH-5606)
Importing unicodedata in sre_parse leads to failure in compilation. unicodedata is unused during compilation, and is not compiled when this file is imported. The error occurs when generating posix variables, pprint is required. The dependency chain goes on like this: sysconfig -> pprint -> re -> sre_compile -> sre_parse (this file) This commits fixes compilation issues introduced by 2272cec. (Issue 30688, GH-5588)
1 parent a445feb commit 5df5286

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Lib/sre_parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# XXX: show string offset and offending character for all errors
1414

1515
from sre_constants import *
16-
import unicodedata
1716

1817
SPECIAL_CHARS = ".\\[{()*+?^$|"
1918
REPEAT_CHARS = "*+?{"
@@ -324,6 +323,7 @@ def _class_escape(source, escape):
324323
chr(c) # raise ValueError for invalid code
325324
return LITERAL, c
326325
elif c == "N" and source.istext:
326+
import unicodedata
327327
# named unicode escape e.g. \N{EM DASH}
328328
if not source.match('{'):
329329
raise source.error("missing {")
@@ -383,6 +383,7 @@ def _escape(source, escape, state):
383383
chr(c) # raise ValueError for invalid code
384384
return LITERAL, c
385385
elif c == "N" and source.istext:
386+
import unicodedata
386387
# named unicode escape e.g. \N{EM DASH}
387388
if not source.match('{'):
388389
raise source.error("missing {")

0 commit comments

Comments
 (0)