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

Add compatibility with python 3.13.1 #2647

Merged
merged 3 commits into from
Dec 8, 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
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ What's New in astroid 3.3.6?
============================
Release date: TBA

* Fix inability to import `collections.abc` in python 3.13.1.

Closes pylint-dev/pylint#10112

* Fix precedence of `path` arg in `modpath_from_file_with_callback` to be higher than `sys.path`


Expand Down
11 changes: 6 additions & 5 deletions astroid/brain/brain_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from astroid.brain.helpers import register_module_extender
from astroid.builder import AstroidBuilder, extract_node, parse
from astroid.const import PY313_PLUS
from astroid.const import PY313_0, PY313_PLUS
from astroid.context import InferenceContext
from astroid.exceptions import AttributeInferenceError
from astroid.manager import AstroidManager
Expand All @@ -20,7 +20,8 @@

def _collections_transform():
return parse(
"""
(" import _collections_abc as abc" if PY313_PLUS and not PY313_0 else "")
+ """
class defaultdict(dict):
default_factory = None
def __missing__(self, key): pass
Expand All @@ -32,7 +33,7 @@ def __getitem__(self, key): return default_factory
)


def _collections_abc_313_transform() -> nodes.Module:
def _collections_abc_313_0_transform() -> nodes.Module:
"""See https://github.com/python/cpython/pull/124735"""
return AstroidBuilder(AstroidManager()).string_build(
"from _collections_abc import *"
Expand Down Expand Up @@ -132,7 +133,7 @@ def register(manager: AstroidManager) -> None:
ClassDef, easy_class_getitem_inference, _looks_like_subscriptable
)

if PY313_PLUS:
if PY313_0:
register_module_extender(
manager, "collections.abc", _collections_abc_313_transform
manager, "collections.abc", _collections_abc_313_0_transform
)
1 change: 1 addition & 0 deletions astroid/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PY311_PLUS = sys.version_info >= (3, 11)
PY312_PLUS = sys.version_info >= (3, 12)
PY313_PLUS = sys.version_info >= (3, 13)
PY313_0 = sys.version_info[:3] == (3, 13, 0)

WIN32 = sys.platform == "win32"

Expand Down
Loading