4
4
5
5
from __future__ import annotations
6
6
7
+ from typing import TYPE_CHECKING
8
+
7
9
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
9
12
from astroid .context import InferenceContext
10
13
from astroid .exceptions import AttributeInferenceError
11
14
from astroid .manager import AstroidManager
12
15
from astroid .nodes .scoped_nodes import ClassDef
13
16
17
+ if TYPE_CHECKING :
18
+ from astroid import nodes
19
+
14
20
15
21
def _collections_transform ():
16
22
return parse (
@@ -26,6 +32,13 @@ def __getitem__(self, key): return default_factory
26
32
)
27
33
28
34
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
+
29
42
def _deque_mock ():
30
43
base_deque_class = """
31
44
class deque(object):
@@ -118,3 +131,8 @@ def register(manager: AstroidManager) -> None:
118
131
manager .register_transform (
119
132
ClassDef , easy_class_getitem_inference , _looks_like_subscriptable
120
133
)
134
+
135
+ if PY313_PLUS :
136
+ register_module_extender (
137
+ manager , "collections.abc" , _collections_abc_313_transform
138
+ )
0 commit comments