Skip to content

Commit

Permalink
Fix python 3.13 compatibility re: collections.abc (#2598) (#2599)
Browse files Browse the repository at this point in the history
(cherry picked from commit f63a393)
  • Loading branch information
jacobtylerwalls authored Oct 4, 2024
1 parent 34c70f0 commit d1f9347
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ What's New in astroid 3.3.5?
============================
Release date: TBA

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

Closes #1490

* Fix Python 3.13 compatibility re: `collections.abc`

Closes pylint-dev/pylint#10000


What's New in astroid 3.3.4?
Expand Down
20 changes: 19 additions & 1 deletion astroid/brain/brain_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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
)

0 comments on commit d1f9347

Please sign in to comment.