Skip to content

Commit

Permalink
Remove _is_compatible_stub_package check from modulefinder (#16633)
Browse files Browse the repository at this point in the history
Closes #16632
  • Loading branch information
sobolevn committed Dec 12, 2023
1 parent 6acccd1 commit 09cb2d1
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@
import subprocess
import sys
from enum import Enum, unique

from mypy.errors import CompileError

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from typing import Dict, Final, List, NamedTuple, Optional, Tuple, Union
from typing_extensions import TypeAlias as _TypeAlias

from mypy import pyinfo
from mypy.errors import CompileError
from mypy.fscache import FileSystemCache
from mypy.nodes import MypyFile
from mypy.options import Options
Expand Down Expand Up @@ -426,7 +419,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
for pkg_dir in self.search_paths.package_path:
stub_name = components[0] + "-stubs"
stub_dir = os.path.join(pkg_dir, stub_name)
if fscache.isdir(stub_dir) and self._is_compatible_stub_package(stub_dir):
if fscache.isdir(stub_dir):
stub_typed_file = os.path.join(stub_dir, "py.typed")
stub_components = [stub_name] + components[1:]
path = os.path.join(pkg_dir, *stub_components[:-1])
Expand Down Expand Up @@ -562,19 +555,6 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
else:
return ModuleNotFoundReason.NOT_FOUND

def _is_compatible_stub_package(self, stub_dir: str) -> bool:
"""Does a stub package support the target Python version?
Stub packages may contain a metadata file which specifies
whether the stubs are compatible with Python 2 and 3.
"""
metadata_fnam = os.path.join(stub_dir, "METADATA.toml")
if not os.path.isfile(metadata_fnam):
return True
with open(metadata_fnam, "rb") as f:
metadata = tomllib.load(f)
return bool(metadata.get("python3", True))

def find_modules_recursive(self, module: str) -> list[BuildSource]:
module_path = self.find_module(module)
if isinstance(module_path, ModuleNotFoundReason):
Expand Down

0 comments on commit 09cb2d1

Please sign in to comment.