Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python 3.13 compatibility re: collections.abc #2598

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
Loading