Skip to content

Commit

Permalink
Exempt numpy from these changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed May 4, 2024
1 parent 7297dde commit 4407867
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ def find_module(
pass
submodule_path = sys.path

# We're looping on pyi first because if a pyi exists there's probably a reason
# (i.e. the code is hard or impossible to parse), so we take pyi into account
# But we're not quite ready to do this for numpy
suffixes = (".pyi", ".py", importlib.machinery.BYTECODE_SUFFIXES[0])
numpy_suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
for entry in submodule_path:
package_directory = os.path.join(entry, modname)
# We're looping on pyi first because if a pyi exists there's probably a reason
# (i.e. the code is hard or impossible to parse), so we take pyi into account
for suffix in (".pyi", ".py", importlib.machinery.BYTECODE_SUFFIXES[0]):
for suffix in numpy_suffixes if "numpy" in entry else suffixes:
package_file_name = "__init__" + suffix
file_path = os.path.join(package_directory, package_file_name)
if os.path.isfile(file_path):
Expand Down
5 changes: 3 additions & 2 deletions astroid/modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def get_source_file(filename: str, include_no_ext: bool = False) -> str:
base, orig_ext = os.path.splitext(filename)
if orig_ext == ".pyi" and os.path.exists(f"{base}{orig_ext}"):
return f"{base}{orig_ext}"
for ext in PY_SOURCE_EXTS:
for ext in PY_SOURCE_EXTS if "numpy" not in filename else reversed(PY_SOURCE_EXTS):
source_path = f"{base}.{ext}"
if os.path.exists(source_path):
return source_path
Expand Down Expand Up @@ -671,7 +671,8 @@ def _has_init(directory: str) -> str | None:
else return None.
"""
mod_or_pack = os.path.join(directory, "__init__")
for ext in (*PY_SOURCE_EXTS, "pyc", "pyo"):
exts = reversed(PY_SOURCE_EXTS) if "numpy" in directory else PY_SOURCE_EXTS
for ext in (*exts, "pyc", "pyo"):
if os.path.exists(mod_or_pack + "." + ext):
return mod_or_pack + "." + ext
return None
Expand Down

0 comments on commit 4407867

Please sign in to comment.