|
7 | 7 | from astroid import context, inference_tip, nodes
|
8 | 8 | from astroid.brain.helpers import register_module_extender
|
9 | 9 | from astroid.builder import _extract_single_node, parse
|
10 |
| -from astroid.const import PY37_PLUS, PY39_PLUS |
| 10 | +from astroid.const import PY37_PLUS, PY39_PLUS, PY311_PLUS |
11 | 11 | from astroid.manager import AstroidManager
|
12 | 12 |
|
13 | 13 |
|
14 |
| -def _re_transform(): |
15 |
| - # Since Python 3.6 there is the RegexFlag enum |
16 |
| - # where every entry will be exposed via updating globals() |
| 14 | +def _re_transform() -> nodes.Module: |
| 15 | + # The RegexFlag enum exposes all its entries by updating globals() |
| 16 | + # On 3.11+ all flags come from re._compiler |
| 17 | + if PY311_PLUS: |
| 18 | + import_compiler = "import re._compiler as _compiler" |
| 19 | + # In 3.6-3.10 all flags come from sre_compile |
| 20 | + else: |
| 21 | + import_compiler = "import sre_compiler as _compiler" |
17 | 22 | return parse(
|
18 |
| - """ |
19 |
| - import sre_compile |
20 |
| - ASCII = sre_compile.SRE_FLAG_ASCII |
21 |
| - IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE |
22 |
| - LOCALE = sre_compile.SRE_FLAG_LOCALE |
23 |
| - UNICODE = sre_compile.SRE_FLAG_UNICODE |
24 |
| - MULTILINE = sre_compile.SRE_FLAG_MULTILINE |
25 |
| - DOTALL = sre_compile.SRE_FLAG_DOTALL |
26 |
| - VERBOSE = sre_compile.SRE_FLAG_VERBOSE |
| 23 | + f""" |
| 24 | + {import_compiler} |
| 25 | + NOFLAG = 0 |
| 26 | + ASCII = _compiler.SRE_FLAG_ASCII |
| 27 | + IGNORECASE = _compiler.SRE_FLAG_IGNORECASE |
| 28 | + LOCALE = _compiler.SRE_FLAG_LOCALE |
| 29 | + UNICODE = _compiler.SRE_FLAG_UNICODE |
| 30 | + MULTILINE = _compiler.SRE_FLAG_MULTILINE |
| 31 | + DOTALL = _compiler.SRE_FLAG_DOTALL |
| 32 | + VERBOSE = _compiler.SRE_FLAG_VERBOSE |
| 33 | + TEMPLATE = _compiler.SRE_FLAG_TEMPLATE |
| 34 | + DEBUG = _compiler.SRE_FLAG_DEBUG |
27 | 35 | A = ASCII
|
28 | 36 | I = IGNORECASE
|
29 | 37 | L = LOCALE
|
30 | 38 | U = UNICODE
|
31 | 39 | M = MULTILINE
|
32 | 40 | S = DOTALL
|
33 | 41 | X = VERBOSE
|
34 |
| - TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE |
35 | 42 | T = TEMPLATE
|
36 |
| - DEBUG = sre_compile.SRE_FLAG_DEBUG |
37 | 43 | """
|
38 | 44 | )
|
39 | 45 |
|
|
0 commit comments