18 IRONPYTHON = (platform.python_implementation() == "IronPython") |
18 IRONPYTHON = (platform.python_implementation() == "IronPython") |
19 |
19 |
20 # Python versions. We amend version_info with one more value, a zero if an |
20 # Python versions. We amend version_info with one more value, a zero if an |
21 # official version, or 1 if built from source beyond an official version. |
21 # official version, or 1 if built from source beyond an official version. |
22 PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),) |
22 PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),) |
23 PY2 = PYVERSION < (3, 0) |
|
24 PY3 = PYVERSION >= (3, 0) |
|
25 |
23 |
26 if PYPY: |
24 if PYPY: |
27 PYPYVERSION = sys.pypy_version_info |
25 PYPYVERSION = sys.pypy_version_info |
28 |
26 |
29 PYPY2 = PYPY and PY2 |
|
30 PYPY3 = PYPY and PY3 |
|
31 |
|
32 # Python behavior. |
27 # Python behavior. |
33 class PYBEHAVIOR(object): |
28 class PYBEHAVIOR: |
34 """Flags indicating this Python's behavior.""" |
29 """Flags indicating this Python's behavior.""" |
35 |
30 |
|
31 # Does Python conform to PEP626, Precise line numbers for debugging and other tools. |
|
32 # https://www.python.org/dev/peps/pep-0626 |
36 pep626 = CPYTHON and (PYVERSION > (3, 10, 0, 'alpha', 4)) |
33 pep626 = CPYTHON and (PYVERSION > (3, 10, 0, 'alpha', 4)) |
37 |
34 |
38 # Is "if __debug__" optimized away? |
35 # Is "if __debug__" optimized away? |
39 if PYPY3: |
36 if PYPY: |
40 optimize_if_debug = True |
37 optimize_if_debug = True |
41 elif PYPY2: |
|
42 optimize_if_debug = False |
|
43 else: |
38 else: |
44 optimize_if_debug = not pep626 |
39 optimize_if_debug = not pep626 |
45 |
40 |
46 # Is "if not __debug__" optimized away? |
41 # Is "if not __debug__" optimized away? |
47 optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
42 optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
48 if pep626: |
43 if pep626: |
49 optimize_if_not_debug = False |
44 optimize_if_not_debug = False |
50 if PYPY3: |
45 if PYPY: |
51 optimize_if_not_debug = True |
46 optimize_if_not_debug = True |
52 |
47 |
53 # Is "if not __debug__" optimized away even better? |
48 # Is "if not __debug__" optimized away even better? |
54 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1)) |
49 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1)) |
55 if pep626: |
50 if pep626: |
56 optimize_if_not_debug2 = False |
51 optimize_if_not_debug2 = False |
57 |
52 |
58 # Do we have yield-from? |
53 # Yet another way to optimize "if not __debug__"? |
59 yield_from = (PYVERSION >= (3, 3)) |
54 optimize_if_not_debug3 = (PYPY and PYVERSION >= (3, 8)) |
60 |
|
61 # Do we have PEP 420 namespace packages? |
|
62 namespaces_pep420 = (PYVERSION >= (3, 3)) |
|
63 |
|
64 # Do .pyc files have the source file size recorded in them? |
|
65 size_in_pyc = (PYVERSION >= (3, 3)) |
|
66 |
|
67 # Do we have async and await syntax? |
|
68 async_syntax = (PYVERSION >= (3, 5)) |
|
69 |
|
70 # PEP 448 defined additional unpacking generalizations |
|
71 unpackings_pep448 = (PYVERSION >= (3, 5)) |
|
72 |
55 |
73 # Can co_lnotab have negative deltas? |
56 # Can co_lnotab have negative deltas? |
74 negative_lnotab = (PYVERSION >= (3, 6)) and not (PYPY and PYPYVERSION < (7, 2)) |
57 negative_lnotab = not (PYPY and PYPYVERSION < (7, 2)) |
75 |
58 |
76 # Do .pyc files conform to PEP 552? Hash-based pyc's. |
59 # Do .pyc files conform to PEP 552? Hash-based pyc's. |
77 hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
60 hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
78 |
61 |
79 # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It |
62 # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It |
80 # used to be an empty string (meaning the current directory). It changed |
63 # used to be an empty string (meaning the current directory). It changed |
81 # to be the actual path to the current directory, so that os.chdir wouldn't |
64 # to be the actual path to the current directory, so that os.chdir wouldn't |
82 # affect the outcome. |
65 # affect the outcome. |
83 actual_syspath0_dash_m = CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3)) |
66 actual_syspath0_dash_m = ( |
|
67 (CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3))) or |
|
68 (PYPY and (PYPYVERSION >= (7, 3, 4))) |
|
69 ) |
84 |
70 |
85 # 3.7 changed how functions with only docstrings are numbered. |
71 # 3.7 changed how functions with only docstrings are numbered. |
86 docstring_only_function = (not PYPY) and ((3, 7, 0, 'beta', 5) <= PYVERSION <= (3, 10)) |
72 docstring_only_function = (not PYPY) and ((3, 7, 0, 'beta', 5) <= PYVERSION <= (3, 10)) |
87 |
73 |
88 # When a break/continue/return statement in a try block jumps to a finally |
74 # When a break/continue/return statement in a try block jumps to a finally |