-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Enable mypy checking for astroid/interpreter/_import/ #2530
Merged
Pierre-Sassoulas
merged 3 commits into
pylint-dev:main
from
correctmost:cm/mypy-for-import-dir
Aug 30, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from collections.abc import Iterable, Iterator, Sequence | ||
from functools import lru_cache | ||
from pathlib import Path | ||
from typing import Any, Literal, NamedTuple, Protocol | ||
from typing import Literal, NamedTuple, Protocol | ||
|
||
from astroid.const import PY310_PLUS | ||
from astroid.modutils import EXT_LIB_DIRS, cached_os_path_isfile | ||
|
@@ -91,7 +91,7 @@ def __init__(self, path: Sequence[str] | None = None) -> None: | |
def find_module( | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> ModuleSpec | None: | ||
"""Find the given module. | ||
|
@@ -130,7 +130,7 @@ class ImportlibFinder(Finder): | |
def find_module( | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> ModuleSpec | None: | ||
if submodule_path is not None: | ||
|
@@ -225,7 +225,7 @@ class ExplicitNamespacePackageFinder(ImportlibFinder): | |
def find_module( | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> ModuleSpec | None: | ||
if processed: | ||
|
@@ -265,7 +265,7 @@ def __init__(self, path: Sequence[str]) -> None: | |
def find_module( | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> ModuleSpec | None: | ||
try: | ||
|
@@ -289,7 +289,7 @@ class PathSpecFinder(Finder): | |
def find_module( | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> ModuleSpec | None: | ||
spec = importlib.machinery.PathFinder.find_spec(modname, path=submodule_path) | ||
|
@@ -346,7 +346,7 @@ def _search_zip( | |
) -> tuple[Literal[ModuleType.PY_ZIPMODULE], str, str]: | ||
for filepath, importer in _get_zipimporters(): | ||
if PY310_PLUS: | ||
found: Any = importer.find_spec(modpath[0]) | ||
found = importer.find_spec(modpath[0]) | ||
else: | ||
found = importer.find_module(modpath[0]) | ||
if found: | ||
|
@@ -373,15 +373,15 @@ def _find_spec_with_path( | |
search_path: Sequence[str], | ||
modname: str, | ||
module_parts: tuple[str], | ||
processed: tuple[str], | ||
processed: tuple[str, ...], | ||
submodule_path: Sequence[str] | None, | ||
) -> tuple[Finder | _MetaPathFinder, ModuleSpec]: | ||
for finder in _SPEC_FINDERS: | ||
finder_instance = finder(search_path) | ||
spec = finder.find_module(modname, module_parts, processed, submodule_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The identifier
|
||
if spec is None: | ||
mod_spec = finder.find_module(modname, module_parts, processed, submodule_path) | ||
if mod_spec is None: | ||
continue | ||
return finder_instance, spec | ||
return finder_instance, mod_spec | ||
|
||
# Support for custom finders | ||
for meta_finder in sys.meta_path: | ||
|
@@ -444,20 +444,19 @@ def find_spec(modpath: Iterable[str], path: Iterable[str] | None = None) -> Modu | |
|
||
|
||
@lru_cache(maxsize=1024) | ||
def _find_spec(module_path: tuple, path: tuple) -> ModuleSpec: | ||
def _find_spec(module_path: tuple[str], path: tuple[str, ...]) -> ModuleSpec: | ||
_path = path or sys.path | ||
|
||
# Need a copy for not mutating the argument. | ||
modpath = list(module_path) | ||
|
||
submodule_path = None | ||
module_parts = tuple(modpath) | ||
processed: list[str] = [] | ||
|
||
while modpath: | ||
modname = modpath.pop(0) | ||
finder, spec = _find_spec_with_path( | ||
_path, modname, module_parts, tuple(processed), submodule_path or path | ||
_path, modname, module_path, tuple(processed), submodule_path or path | ||
) | ||
processed.append(modname) | ||
if modpath: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still exclude testdata right?nvm, saw that everything happens in the pyproject.toml now.