File: utilpyversion.py

package info (click to toggle)
python-beartype 0.22.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,504 kB
  • sloc: python: 85,502; sh: 328; makefile: 30; javascript: 18
file content (190 lines) | stat: -rw-r--r-- 6,109 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
# --------------------( LICENSE                            )--------------------
# Copyright (c) 2014-2025 Beartype authors.
# See "LICENSE" for further details.

'''
Project-wide **Python interpreter version utilities**.

This private submodule is *not* intended for importation by downstream callers.
'''

# ....................{ IMPORTS                            }....................
from sys import version_info

# ....................{ CONSTANTS                          }....................
# While cumbersome, the current approach is substantially faster than automated
# alternatives (e.g., dictionary subclasses overriding the __missing__() dunder
# method to implement crude caches). Faster >>>> every other concern here, as
# Python interpreter version checks appear so frequently in critical code paths.

IS_PYTHON_AT_LEAST_4_0 = version_info >= (4, 0)
'''
:data:`True` only if the active Python interpreter targets at least Python
4.0.0.
'''


#FIXME: After dropping Python 3.16 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.17.0')
IS_PYTHON_AT_LEAST_3_17 = IS_PYTHON_AT_LEAST_4_0 or version_info >= (3, 17)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.17.0.
'''


#FIXME: After dropping Python 3.16 support:
#* Remove all code conditionally testing this global.
#* Remove this global.
IS_PYTHON_AT_MOST_3_16 = not IS_PYTHON_AT_LEAST_3_17
'''
:data:`True` only if the active Python interpreter targets at most Python
3.16.x.
'''


#FIXME: After dropping Python 3.15 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.16.0')
IS_PYTHON_AT_LEAST_3_16 = IS_PYTHON_AT_LEAST_3_17 or version_info >= (3, 16)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.16.0.
'''


#FIXME: After dropping Python 3.15 support:
#* Remove all code conditionally testing this global.
#* Remove this global.
IS_PYTHON_AT_MOST_3_15 = not IS_PYTHON_AT_LEAST_3_16
'''
:data:`True` only if the active Python interpreter targets at most Python
3.15.x.
'''


#FIXME: After dropping Python 3.14 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.15.0')
IS_PYTHON_AT_LEAST_3_15 = IS_PYTHON_AT_LEAST_3_16 or version_info >= (3, 15)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.15.0.
'''


#FIXME: Preserved if we ever require this. *shrug*
# #FIXME: After dropping Python 3.14 support:
# #* Remove all code conditionally testing this global.
# #* Remove this global.
# IS_PYTHON_AT_MOST_3_14 = not IS_PYTHON_AT_LEAST_3_15
# '''
# :data:`True` only if the active Python interpreter targets at most Python
# 3.14.x.
# '''


#FIXME: After dropping Python 3.13 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.14.0')
IS_PYTHON_AT_LEAST_3_14 = IS_PYTHON_AT_LEAST_3_15 or version_info >= (3, 14)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.14.0.
'''


#FIXME: After dropping Python 3.13 support:
#* Remove all code conditionally testing this global.
#* Remove this global.
IS_PYTHON_AT_MOST_3_13 = not IS_PYTHON_AT_LEAST_3_14
'''
:data:`True` only if the active Python interpreter targets at most Python
3.13.x.
'''


#FIXME: After dropping Python 3.12 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.13.0')
IS_PYTHON_AT_LEAST_3_13 = IS_PYTHON_AT_LEAST_3_14 or version_info >= (3, 13)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.13.0.
'''


#FIXME: After dropping Python 3.11 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.12.0')
IS_PYTHON_AT_LEAST_3_12 = IS_PYTHON_AT_LEAST_3_13 or version_info >= (3, 12)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.13.0.
'''


#FIXME: After dropping Python 3.11 support:
#* Remove all code conditionally testing this global.
#* Remove this global.
IS_PYTHON_AT_MOST_3_11 = not IS_PYTHON_AT_LEAST_3_12
'''
:data:`True` only if the active Python interpreter targets at most Python
3.11.x.
'''


#FIXME: After dropping Python 3.10 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
#* Remove all decorators resembling:
#  @skip_if_python_version_less_than('3.11.0')
IS_PYTHON_AT_LEAST_3_11 = IS_PYTHON_AT_LEAST_3_12 or version_info >= (3, 11)
'''
:data:`True` only if the active Python interpreter targets at least Python
3.11.0.
'''


#FIXME: After dropping Python 3.11 support:
#* Refactor all code conditionally testing this global to be unconditional.
#* Remove this global.
IS_PYTHON_3_11 = version_info[:2] == (3, 11)
'''
:data:`True` only if the active Python interpreter targets exactly Python
3.11.x.
'''


#FIXME: After dropping Python 3.10 support:
#* Remove all code conditionally testing this global.
#* Remove this global.
IS_PYTHON_AT_MOST_3_10 = not IS_PYTHON_AT_LEAST_3_11
'''
:data:`True` only if the active Python interpreter targets at most Python
3.10.x.
'''

# ....................{ GETTERS                            }....................
def get_python_version_major_minor() -> str:
    '''
    ``"."``-delimited major and minor version of the active Python interpreter
    (e.g., ``3.11``, ``3.7``), excluding the patch version of this interpreter.
    '''

    # Heroic one-liners are an inspiration to us all.
    return f'{version_info[0]}.{version_info[1]}'