Skip to content

Commit f63a393

Browse files
Fix python 3.13 compatibility re: collections.abc (#2598)
1 parent 6dba72c commit f63a393

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ChangeLog

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ Release date: TBA
2222

2323
* Control setting local nodes outside of the supposed local's constructor.
2424

25-
Closes pylint-dev/astroid/issues/1490
25+
Closes #1490
26+
27+
* Fix Python 3.13 compatibility re: `collections.abc`
28+
29+
Closes pylint-dev/pylint#10000
2630

2731

2832
What's New in astroid 3.3.4?

astroid/brain/brain_collections.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
from __future__ import annotations
66

7+
from typing import TYPE_CHECKING
8+
79
from astroid.brain.helpers import register_module_extender
8-
from astroid.builder import extract_node, parse
10+
from astroid.builder import AstroidBuilder, extract_node, parse
11+
from astroid.const import PY313_PLUS
912
from astroid.context import InferenceContext
1013
from astroid.exceptions import AttributeInferenceError
1114
from astroid.manager import AstroidManager
1215
from astroid.nodes.scoped_nodes import ClassDef
1316

17+
if TYPE_CHECKING:
18+
from astroid import nodes
19+
1420

1521
def _collections_transform():
1622
return parse(
@@ -26,6 +32,13 @@ def __getitem__(self, key): return default_factory
2632
)
2733

2834

35+
def _collections_abc_313_transform() -> nodes.Module:
36+
"""See https://github.com/python/cpython/pull/124735"""
37+
return AstroidBuilder(AstroidManager()).string_build(
38+
"from _collections_abc import *"
39+
)
40+
41+
2942
def _deque_mock():
3043
base_deque_class = """
3144
class deque(object):
@@ -118,3 +131,8 @@ def register(manager: AstroidManager) -> None:
118131
manager.register_transform(
119132
ClassDef, easy_class_getitem_inference, _looks_like_subscriptable
120133
)
134+
135+
if PY313_PLUS:
136+
register_module_extender(
137+
manager, "collections.abc", _collections_abc_313_transform
138+
)

0 commit comments

Comments
 (0)