11 """ |
11 """ |
12 |
12 |
13 import ast |
13 import ast |
14 import sys |
14 import sys |
15 from enum import IntEnum, auto |
15 from enum import IntEnum, auto |
16 from contextlib import contextmanager, nullcontext |
16 from contextlib import contextmanager |
17 |
17 |
18 import AstUtilities |
18 import AstUtilities |
|
19 |
|
20 try: |
|
21 from contextlib import nullcontext |
|
22 except ImportError: |
|
23 # 'nullcontext'' was defined in Python 3.7. The following code is a copy |
|
24 # of that class. |
|
25 |
|
26 from contextlib import AbstractContextManager |
|
27 |
|
28 class nullcontext(AbstractContextManager): |
|
29 """Context manager that does no additional processing. |
|
30 |
|
31 Used as a stand-in for a normal context manager, when a particular |
|
32 block of code is only sometimes used with a normal context manager: |
|
33 |
|
34 cm = optional_cm if condition else nullcontext() |
|
35 with cm: |
|
36 # Perform operation, using optional_cm if condition is True |
|
37 """ |
|
38 |
|
39 def __init__(self, enter_result=None): |
|
40 self.enter_result = enter_result |
|
41 |
|
42 def __enter__(self): |
|
43 return self.enter_result |
|
44 |
|
45 def __exit__(self, *excinfo): |
|
46 pass |
19 |
47 |
20 # Large float and imaginary literals get turned into infinities in the AST. |
48 # Large float and imaginary literals get turned into infinities in the AST. |
21 # We unparse those infinities to INFSTR. |
49 # We unparse those infinities to INFSTR. |
22 _INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1) |
50 _INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1) |
23 |
51 |