From 43eb6d7b196c24d4aef0c85210dc6ef035d57e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 24 Dec 2024 01:38:36 +0100 Subject: [PATCH 1/3] Another attempt at fixing the `collections.abc` issue for Python 3.13 (#2665) * Fix issue with importing of frozen submodules (cherry picked from commit f94e855268895bf995fe8eb258ea7ff7d7ccd9cf) --- ChangeLog | 6 +++ astroid/interpreter/_import/spec.py | 60 ++++++++++++++++------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ec03e2fa..d20554ec0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,12 +13,18 @@ What's New in astroid 3.3.8? ============================ Release date: TBA +* Fix inability to import `collections.abc` in python 3.13.1. The reported fixes in astroid 3.3.6 + and 3.3.7 did not actually fix this issue. + + Closes pylint-dev/pylint#10112 What's New in astroid 3.3.7? ============================ Release date: 2024-12-20 +This release was yanked. + * Fix inability to import `collections.abc` in python 3.13.1. The reported fix in astroid 3.3.6 did not actually fix this issue. diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index 832432d94..fd53da56e 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -142,15 +142,45 @@ def find_module( type=ModuleType.C_BUILTIN, ) + if submodule_path is not None: + search_paths = list(submodule_path) + else: + search_paths = sys.path + + suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0]) + for entry in search_paths: + package_directory = os.path.join(entry, modname) + for suffix in suffixes: + package_file_name = "__init__" + suffix + file_path = os.path.join(package_directory, package_file_name) + if os.path.isfile(file_path): + return ModuleSpec( + name=modname, + location=package_directory, + type=ModuleType.PKG_DIRECTORY, + ) + for suffix, type_ in ImportlibFinder._SUFFIXES: + file_name = modname + suffix + file_path = os.path.join(entry, file_name) + if os.path.isfile(file_path): + return ModuleSpec(name=modname, location=file_path, type=type_) + # sys.stdlib_module_names was added in Python 3.10 if PY310_PLUS: - # If the module is a stdlib module, check whether this is a frozen module. Note that - # `find_spec` actually imports the module, so we want to make sure we only run this code - # for stuff that can be expected to be frozen. For now this is only stdlib. + # If the module name matches a stdlib module name, check whether this is a frozen + # module. Note that `find_spec` actually imports parent modules, so we want to make + # sure we only run this code for stuff that can be expected to be frozen. For now + # this is only stdlib. if modname in sys.stdlib_module_names or ( processed and processed[0] in sys.stdlib_module_names ): - spec = importlib.util.find_spec(".".join((*processed, modname))) + try: + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=Warning) + spec = importlib.util.find_spec(".".join((*processed, modname))) + except ValueError: + spec = None + if ( spec and spec.loader # type: ignore[comparison-overlap] # noqa: E501 @@ -186,28 +216,6 @@ def find_module( except ValueError: pass - if submodule_path is not None: - search_paths = list(submodule_path) - else: - search_paths = sys.path - - suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0]) - for entry in search_paths: - package_directory = os.path.join(entry, modname) - for suffix in suffixes: - package_file_name = "__init__" + suffix - file_path = os.path.join(package_directory, package_file_name) - if os.path.isfile(file_path): - return ModuleSpec( - name=modname, - location=package_directory, - type=ModuleType.PKG_DIRECTORY, - ) - for suffix, type_ in ImportlibFinder._SUFFIXES: - file_name = modname + suffix - file_path = os.path.join(entry, file_name) - if os.path.isfile(file_path): - return ModuleSpec(name=modname, location=file_path, type=type_) return None def contribute_to_path( From b5319d5ba2adde8f24c0b1a0d0dcc0516be29422 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 8 Oct 2024 07:20:37 -0400 Subject: [PATCH 2/3] Test on Python 3.13 final --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ae694e6b..fd0fb7f9b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -81,7 +81,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9, "3.10", "3.11", "3.12", "3.13-dev"] + python-version: [3.9, "3.10", "3.11", "3.12", "3.13"] outputs: python-key: ${{ steps.generate-python-key.outputs.key }} steps: @@ -138,7 +138,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9, "3.10", "3.11", "3.12", "3.13-dev"] + python-version: [3.9, "3.10", "3.11", "3.12", "3.13"] steps: - name: Set temp directory run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV From 9b540516ceb8e5d2eb8e2347c892463d93bd3a41 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 8 Oct 2024 07:21:51 -0400 Subject: [PATCH 3/3] Bump CI jobs to python 3.13 --- .github/workflows/ci.yaml | 6 +++--- .github/workflows/release.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fd0fb7f9b..5b689dbd5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ on: env: CACHE_VERSION: 3 KEY_PREFIX: venv - DEFAULT_PYTHON: "3.12" + DEFAULT_PYTHON: "3.13" PRE_COMMIT_CACHE: ~/.cache/pre-commit concurrency: @@ -242,11 +242,11 @@ jobs: steps: - name: Check out code from GitHub uses: actions/checkout@v4.1.7 - - name: Set up Python 3.12 + - name: Set up Python 3.13 id: python uses: actions/setup-python@v5.1.1 with: - python-version: "3.12" + python-version: "3.13" check-latest: true - name: Install dependencies run: pip install -U -r requirements_minimal.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d527a2f22..ff91c7fd5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: - published env: - DEFAULT_PYTHON: "3.12" + DEFAULT_PYTHON: "3.13" permissions: contents: read