Skip to content

Commit 7ff0f4f

Browse files
Drop support for Python 3.8 (#2443)
Also remove constants `PY38`, `PY39_PLUS`, and `PYPY_7_3_11_PLUS`.
1 parent 03db5c1 commit 7ff0f4f

38 files changed

+114
-433
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
strategy:
8282
fail-fast: false
8383
matrix:
84-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
84+
python-version: [3.9, "3.10", "3.11", "3.12"]
8585
outputs:
8686
python-key: ${{ steps.generate-python-key.outputs.key }}
8787
steps:
@@ -138,7 +138,7 @@ jobs:
138138
strategy:
139139
fail-fast: false
140140
matrix:
141-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
141+
python-version: [3.9, "3.10", "3.11", "3.12"]
142142
steps:
143143
- name: Set temp directory
144144
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
@@ -192,7 +192,7 @@ jobs:
192192
fail-fast: false
193193
matrix:
194194
# We only test on the lowest and highest supported PyPy versions
195-
python-version: ["pypy3.8", "pypy3.10"]
195+
python-version: ["pypy3.9", "pypy3.10"]
196196
steps:
197197
- name: Check out code from GitHub
198198
uses: actions/[email protected]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repos:
2727
hooks:
2828
- id: pyupgrade
2929
exclude: tests/testdata
30-
args: [--py38-plus]
30+
args: [--py39-plus]
3131
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
3232
rev: v1.1.3
3333
hooks:

ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ What's New in astroid 3.3.0?
77
============================
88
Release date: TBA
99

10+
* Remove support for Python 3.8 (and constants `PY38`, `PY39_PLUS`, and `PYPY_7_3_11_PLUS`).
11+
12+
Refs #2443
1013

1114

1215
What's New in astroid 3.2.3?
1316
============================
1417
Release date: TBA
1518

1619

17-
1820
What's New in astroid 3.2.2?
1921
============================
2022
Release date: 2024-05-20

astroid/_backport_stdlib_names.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,7 @@
346346
}
347347
)
348348

349-
if sys.version_info[:2] == (3, 7):
350-
stdlib_module_names = PY_3_7
351-
elif sys.version_info[:2] == (3, 8):
352-
stdlib_module_names = PY_3_8
353-
elif sys.version_info[:2] == (3, 9):
349+
if sys.version_info[:2] == (3, 9):
354350
stdlib_module_names = PY_3_9
355351
else:
356352
raise AssertionError("This module is only intended as a backport for Python <= 3.9")

astroid/brain/brain_builtin_inference.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from __future__ import annotations
88

99
import itertools
10-
from collections.abc import Callable, Iterable
10+
from collections.abc import Callable, Iterable, Iterator
1111
from functools import partial
12-
from typing import TYPE_CHECKING, Any, Iterator, NoReturn, Type, Union, cast
12+
from typing import TYPE_CHECKING, Any, NoReturn, Union, cast
1313

1414
from astroid import arguments, helpers, inference_tip, nodes, objects, util
1515
from astroid.builder import AstroidBuilder
@@ -40,10 +40,10 @@
4040
]
4141

4242
BuiltContainers = Union[
43-
Type[tuple],
44-
Type[list],
45-
Type[set],
46-
Type[frozenset],
43+
type[tuple],
44+
type[list],
45+
type[set],
46+
type[frozenset],
4747
]
4848

4949
CopyResult = Union[

astroid/brain/brain_collections.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from astroid.brain.helpers import register_module_extender
88
from astroid.builder import extract_node, parse
9-
from astroid.const import PY39_PLUS
109
from astroid.context import InferenceContext
1110
from astroid.exceptions import AttributeInferenceError
1211
from astroid.manager import AstroidManager
@@ -61,9 +60,7 @@ def __add__(self, other): pass
6160
def __iadd__(self, other): pass
6261
def __mul__(self, other): pass
6362
def __imul__(self, other): pass
64-
def __rmul__(self, other): pass"""
65-
if PY39_PLUS:
66-
base_deque_class += """
63+
def __rmul__(self, other): pass
6764
@classmethod
6865
def __class_getitem__(self, item): return cls"""
6966
return base_deque_class
@@ -73,9 +70,7 @@ def _ordered_dict_mock():
7370
base_ordered_dict_class = """
7471
class OrderedDict(dict):
7572
def __reversed__(self): return self[::-1]
76-
def move_to_end(self, key, last=False): pass"""
77-
if PY39_PLUS:
78-
base_ordered_dict_class += """
73+
def move_to_end(self, key, last=False): pass
7974
@classmethod
8075
def __class_getitem__(cls, item): return cls"""
8176
return base_ordered_dict_class
@@ -116,11 +111,10 @@ def easy_class_getitem_inference(node, context: InferenceContext | None = None):
116111
def register(manager: AstroidManager) -> None:
117112
register_module_extender(manager, "collections", _collections_transform)
118113

119-
if PY39_PLUS:
120-
# Starting with Python39 some objects of the collection module are subscriptable
121-
# thanks to the __class_getitem__ method but the way it is implemented in
122-
# _collection_abc makes it difficult to infer. (We would have to handle AssignName inference in the
123-
# getitem method of the ClassDef class) Instead we put here a mock of the __class_getitem__ method
124-
manager.register_transform(
125-
ClassDef, easy_class_getitem_inference, _looks_like_subscriptable
126-
)
114+
# Starting with Python39 some objects of the collection module are subscriptable
115+
# thanks to the __class_getitem__ method but the way it is implemented in
116+
# _collection_abc makes it difficult to infer. (We would have to handle AssignName inference in the
117+
# getitem method of the ClassDef class) Instead we put here a mock of the __class_getitem__ method
118+
manager.register_transform(
119+
ClassDef, easy_class_getitem_inference, _looks_like_subscriptable
120+
)

astroid/brain/brain_dataclasses.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
from __future__ import annotations
1616

1717
from collections.abc import Iterator
18-
from typing import Literal, Tuple, Union
18+
from typing import Literal, Union
1919

2020
from astroid import bases, context, nodes
2121
from astroid.builder import parse
22-
from astroid.const import PY39_PLUS, PY310_PLUS
22+
from astroid.const import PY310_PLUS
2323
from astroid.exceptions import AstroidSyntaxError, InferenceError, UseInferenceDefault
2424
from astroid.inference_tip import inference_tip
2525
from astroid.manager import AstroidManager
@@ -28,8 +28,8 @@
2828

2929
_FieldDefaultReturn = Union[
3030
None,
31-
Tuple[Literal["default"], nodes.NodeNG],
32-
Tuple[Literal["default_factory"], nodes.Call],
31+
tuple[Literal["default"], nodes.NodeNG],
32+
tuple[Literal["default_factory"], nodes.Call],
3333
]
3434

3535
DATACLASSES_DECORATORS = frozenset(("dataclass",))
@@ -539,22 +539,12 @@ def _get_field_default(field_call: nodes.Call) -> _FieldDefaultReturn:
539539

540540
def _is_class_var(node: nodes.NodeNG) -> bool:
541541
"""Return True if node is a ClassVar, with or without subscripting."""
542-
if PY39_PLUS:
543-
try:
544-
inferred = next(node.infer())
545-
except (InferenceError, StopIteration):
546-
return False
547-
548-
return getattr(inferred, "name", "") == "ClassVar"
542+
try:
543+
inferred = next(node.infer())
544+
except (InferenceError, StopIteration):
545+
return False
549546

550-
# Before Python 3.9, inference returns typing._SpecialForm instead of ClassVar.
551-
# Our backup is to inspect the node's structure.
552-
return isinstance(node, nodes.Subscript) and (
553-
isinstance(node.value, nodes.Name)
554-
and node.value.name == "ClassVar"
555-
or isinstance(node.value, nodes.Attribute)
556-
and node.value.attrname == "ClassVar"
557-
)
547+
return getattr(inferred, "name", "") == "ClassVar"
558548

559549

560550
def _is_keyword_only_sentinel(node: nodes.NodeNG) -> bool:

astroid/brain/brain_hashlib.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
from astroid.brain.helpers import register_module_extender
66
from astroid.builder import parse
7-
from astroid.const import PY39_PLUS
87
from astroid.manager import AstroidManager
98

109

1110
def _hashlib_transform():
12-
maybe_usedforsecurity = ", usedforsecurity=True" if PY39_PLUS else ""
13-
init_signature = f"value=''{maybe_usedforsecurity}"
11+
init_signature = "value='', usedforsecurity=True"
1412
digest_signature = "self"
1513
shake_digest_signature = "self, length"
1614

@@ -54,13 +52,13 @@ def digest_size(self):
5452
blake2b_signature = (
5553
"data=b'', *, digest_size=64, key=b'', salt=b'', "
5654
"person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, "
57-
f"node_depth=0, inner_size=0, last_node=False{maybe_usedforsecurity}"
55+
"node_depth=0, inner_size=0, last_node=False, usedforsecurity=True"
5856
)
5957

6058
blake2s_signature = (
6159
"data=b'', *, digest_size=32, key=b'', salt=b'', "
6260
"person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, "
63-
f"node_depth=0, inner_size=0, last_node=False{maybe_usedforsecurity}"
61+
"node_depth=0, inner_size=0, last_node=False, usedforsecurity=True"
6462
)
6563

6664
shake_algorithms = dict.fromkeys(

astroid/brain/brain_re.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from astroid import context, inference_tip, nodes
88
from astroid.brain.helpers import register_module_extender
99
from astroid.builder import _extract_single_node, parse
10-
from astroid.const import PY39_PLUS, PY311_PLUS
10+
from astroid.const import PY311_PLUS
1111
from astroid.manager import AstroidManager
1212

1313

@@ -84,9 +84,8 @@ def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext | None =
8484
end_lineno=node.end_lineno,
8585
end_col_offset=node.end_col_offset,
8686
)
87-
if PY39_PLUS:
88-
func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
89-
class_def.locals["__class_getitem__"] = [func_to_add]
87+
func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
88+
class_def.locals["__class_getitem__"] = [func_to_add]
9089
return iter([class_def])
9190

9291

astroid/brain/brain_regex.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from astroid import context, inference_tip, nodes
88
from astroid.brain.helpers import register_module_extender
99
from astroid.builder import _extract_single_node, parse
10-
from astroid.const import PY39_PLUS
1110
from astroid.manager import AstroidManager
1211

1312

@@ -83,9 +82,8 @@ def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext | None =
8382
end_lineno=node.end_lineno,
8483
end_col_offset=node.end_col_offset,
8584
)
86-
if PY39_PLUS:
87-
func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
88-
class_def.locals["__class_getitem__"] = [func_to_add]
85+
func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
86+
class_def.locals["__class_getitem__"] = [func_to_add]
8987
return iter([class_def])
9088

9189

0 commit comments

Comments
 (0)