Skip to content

Commit 0834156

Browse files
Add compatibility with python 3.13.1 (#2647) (#2649)
Refs python/cpython#125415 (cherry picked from commit fe01bda)
1 parent 80ce031 commit 0834156

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ What's New in astroid 3.3.6?
1313
============================
1414
Release date: TBA
1515

16+
* Fix inability to import `collections.abc` in python 3.13.1.
17+
18+
Closes pylint-dev/pylint#10112
19+
1620
* Fix crash when typing._alias() call is missing arguments.
1721

1822
Closes #2513
1923

2024

21-
2225
What's New in astroid 3.3.5?
2326
============================
2427
Release date: 2024-10-04

astroid/brain/brain_collections.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from astroid.brain.helpers import register_module_extender
1010
from astroid.builder import AstroidBuilder, extract_node, parse
11-
from astroid.const import PY313_PLUS
11+
from astroid.const import PY313_0, PY313_PLUS
1212
from astroid.context import InferenceContext
1313
from astroid.exceptions import AttributeInferenceError
1414
from astroid.manager import AstroidManager
@@ -20,7 +20,8 @@
2020

2121
def _collections_transform():
2222
return parse(
23-
"""
23+
(" import _collections_abc as abc" if PY313_PLUS and not PY313_0 else "")
24+
+ """
2425
class defaultdict(dict):
2526
default_factory = None
2627
def __missing__(self, key): pass
@@ -32,7 +33,7 @@ def __getitem__(self, key): return default_factory
3233
)
3334

3435

35-
def _collections_abc_313_transform() -> nodes.Module:
36+
def _collections_abc_313_0_transform() -> nodes.Module:
3637
"""See https://github.com/python/cpython/pull/124735"""
3738
return AstroidBuilder(AstroidManager()).string_build(
3839
"from _collections_abc import *"
@@ -132,7 +133,7 @@ def register(manager: AstroidManager) -> None:
132133
ClassDef, easy_class_getitem_inference, _looks_like_subscriptable
133134
)
134135

135-
if PY313_PLUS:
136+
if PY313_0:
136137
register_module_extender(
137-
manager, "collections.abc", _collections_abc_313_transform
138+
manager, "collections.abc", _collections_abc_313_0_transform
138139
)

astroid/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
PY311_PLUS = sys.version_info >= (3, 11)
1010
PY312_PLUS = sys.version_info >= (3, 12)
1111
PY313_PLUS = sys.version_info >= (3, 13)
12+
PY313_0 = sys.version_info[:3] == (3, 13, 0)
1213

1314
WIN32 = sys.platform == "win32"
1415

0 commit comments

Comments
 (0)