Skip to content

Commit 0e4c869

Browse files
authored
Ignore installed stub and inline packages if use_builtins_fixtures is set (#5554)
Fixes #5553 The idea is simple, while running tests we should ignore real third-party stub/inline packages and use our own fixtures for everything.
1 parent 8b0f022 commit 0e4c869

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

mypy/build.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def default_flush_errors(new_messages: List[str], is_serious: bool) -> None:
194194
raise
195195

196196

197-
# python_path is usercode, mypy_path is set via config or environment variable,
197+
# python_path is user code, mypy_path is set via config or environment variable,
198198
# package_path is calculated by _get_site_packages_dirs, and typeshed_path points
199199
# to typeshed. Each is a tuple of paths to be searched in find_module()
200200
SearchPaths = NamedTuple('SearchPaths',
@@ -676,7 +676,7 @@ def __init__(self, data_dir: str,
676676
self.cache_enabled = options.incremental and (
677677
not options.fine_grained_incremental or options.use_fine_grained_cache)
678678
self.fscache = fscache
679-
self.find_module_cache = FindModuleCache(self.fscache)
679+
self.find_module_cache = FindModuleCache(self.fscache, self.options)
680680

681681
# a mapping from source files to their corresponding shadow files
682682
# for efficient lookup
@@ -854,12 +854,14 @@ class FindModuleCache:
854854
cleared by client code.
855855
"""
856856

857-
def __init__(self, fscache: Optional[FileSystemCache] = None) -> None:
857+
def __init__(self, fscache: Optional[FileSystemCache] = None,
858+
options: Optional[Options] = None) -> None:
858859
self.fscache = fscache or FileSystemCache()
859860
# Cache find_lib_path_dirs: (dir_chain, search_paths) -> list(package_dirs, should_verify)
860861
self.dirs = {} # type: Dict[Tuple[str, Tuple[str, ...]], PackageDirs]
861862
# Cache find_module: (id, search_paths, python_version) -> result.
862863
self.results = {} # type: Dict[Tuple[str, SearchPaths, Optional[str]], Optional[str]]
864+
self.options = options
863865

864866
def clear(self) -> None:
865867
self.results.clear()
@@ -935,6 +937,10 @@ def _find_module(self, id: str, search_paths: SearchPaths,
935937
elif fscache.isfile(typed_file):
936938
path = os.path.join(pkg_dir, dir_chain)
937939
third_party_inline_dirs.append((path, True))
940+
if self.options and self.options.use_builtins_fixtures:
941+
# Everything should be in fixtures.
942+
third_party_inline_dirs.clear()
943+
third_party_stubs_dirs.clear()
938944
python_mypy_path = search_paths.python_path + search_paths.mypy_path
939945
candidate_base_dirs = self.find_lib_path_dirs(dir_chain, python_mypy_path) + \
940946
third_party_stubs_dirs + third_party_inline_dirs + \

mypy/test/testpep561.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from mypy.test.helpers import run_command
1212
from mypy.util import try_find_python2_interpreter
1313

14+
# NOTE: options.use_builtins_fixtures should not be set in these
15+
# tests, otherwise mypy will ignore installed third-party packages.
16+
1417
SIMPLE_PROGRAM = """
1518
from typedpkg.sample import ex
1619
from typedpkg import dne

0 commit comments

Comments
 (0)