Skip to content

Ignore installed stub and inline packages if use_builtins_fixtures is set #5554

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

Merged
merged 3 commits into from
Sep 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def default_flush_errors(new_messages: List[str], is_serious: bool) -> None:
raise


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

# a mapping from source files to their corresponding shadow files
# for efficient lookup
Expand Down Expand Up @@ -854,12 +854,14 @@ class FindModuleCache:
cleared by client code.
"""

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

def clear(self) -> None:
self.results.clear()
Expand Down Expand Up @@ -935,6 +937,10 @@ def _find_module(self, id: str, search_paths: SearchPaths,
elif fscache.isfile(typed_file):
path = os.path.join(pkg_dir, dir_chain)
third_party_inline_dirs.append((path, True))
if self.options and self.options.use_builtins_fixtures:
# Everything should be in fixtures.
third_party_inline_dirs.clear()
third_party_stubs_dirs.clear()
python_mypy_path = search_paths.python_path + search_paths.mypy_path
candidate_base_dirs = self.find_lib_path_dirs(dir_chain, python_mypy_path) + \
third_party_stubs_dirs + third_party_inline_dirs + \
Expand Down
3 changes: 3 additions & 0 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from mypy.test.helpers import run_command
from mypy.util import try_find_python2_interpreter

# NOTE: options.use_builtins_fixtures should not be set in these
# tests, otherwise mypy will ignore installed third-party packages.

SIMPLE_PROGRAM = """
from typedpkg.sample import ex
from typedpkg import dne
Expand Down