diff --git a/ChangeLog b/ChangeLog index f607d78f7..cc29f2a52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,7 +22,11 @@ Release date: TBA * Control setting local nodes outside of the supposed local's constructor. - Closes pylint-dev/astroid/issues/1490 + Closes #1490 + +* Fix Python 3.13 compatibility re: `collections.abc` + + Closes pylint-dev/pylint#10000 What's New in astroid 3.3.4? diff --git a/astroid/brain/brain_collections.py b/astroid/brain/brain_collections.py index 22017786a..94944e67a 100644 --- a/astroid/brain/brain_collections.py +++ b/astroid/brain/brain_collections.py @@ -4,13 +4,19 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from astroid.brain.helpers import register_module_extender -from astroid.builder import extract_node, parse +from astroid.builder import AstroidBuilder, extract_node, parse +from astroid.const import PY313_PLUS from astroid.context import InferenceContext from astroid.exceptions import AttributeInferenceError from astroid.manager import AstroidManager from astroid.nodes.scoped_nodes import ClassDef +if TYPE_CHECKING: + from astroid import nodes + def _collections_transform(): return parse( @@ -26,6 +32,13 @@ def __getitem__(self, key): return default_factory ) +def _collections_abc_313_transform() -> nodes.Module: + """See https://github.com/python/cpython/pull/124735""" + return AstroidBuilder(AstroidManager()).string_build( + "from _collections_abc import *" + ) + + def _deque_mock(): base_deque_class = """ class deque(object): @@ -118,3 +131,8 @@ def register(manager: AstroidManager) -> None: manager.register_transform( ClassDef, easy_class_getitem_inference, _looks_like_subscriptable ) + + if PY313_PLUS: + register_module_extender( + manager, "collections.abc", _collections_abc_313_transform + )