44
55from __future__ import annotations
66
7+ from typing import TYPE_CHECKING
8+
79from 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
912from astroid .context import InferenceContext
1013from astroid .exceptions import AttributeInferenceError
1114from astroid .manager import AstroidManager
1215from astroid .nodes .scoped_nodes import ClassDef
1316
17+ if TYPE_CHECKING :
18+ from astroid import nodes
19+
1420
1521def _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+
2942def _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