Skip to content

Commit d1f9347

Browse files
Fix python 3.13 compatibility re: collections.abc (#2598) (#2599)
(cherry picked from commit f63a393)
1 parent 34c70f0 commit d1f9347

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ What's New in astroid 3.3.5?
1313
============================
1414
Release date: TBA
1515

16+
* Control setting local nodes outside of the supposed local's constructor.
17+
18+
Closes #1490
19+
20+
* Fix Python 3.13 compatibility re: `collections.abc`
21+
22+
Closes pylint-dev/pylint#10000
1623

1724

1825
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)