From 09cb2d17cd16003937835b78bde9a6dbe627204c Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 13 Dec 2023 02:35:45 +0300 Subject: [PATCH] Remove `_is_compatible_stub_package` check from `modulefinder` (#16633) Closes https://github.com/python/mypy/issues/16632 --- mypy/modulefinder.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index c36a382848bf..455aa40e5975 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -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 @@ -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]) @@ -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):