Skip to content

Commit fe01bda

Browse files
Add compatibility with python 3.13.1 (#2647)
Refs python/cpython#125415
1 parent cae4388 commit fe01bda

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ What's New in astroid 3.3.6?
3131
============================
3232
Release date: TBA
3333

34+
* Fix inability to import `collections.abc` in python 3.13.1.
35+
36+
Closes pylint-dev/pylint#10112
37+
3438
* Fix precedence of `path` arg in `modpath_from_file_with_callback` to be higher than `sys.path`
3539

3640

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)