Skip to content

Commit

Permalink
Fix python 3.13 compatibility re: collections.abc (pylint-dev#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Oct 4, 2024
1 parent 6dba72c commit f63a393
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
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 f63a393

Please sign in to comment.