Skip to content

Commit cadecd6

Browse files
committed
Fix incremental issue with namespace packages
Fixes python#12664 See python#18907 which is another possible fix I'm not sure why this logic is actually needed given that we should record the dependency from import analysis in fastparse... maybe just because it adjusts priority? I can't write a good test for this because it requires something in site_packages, but here's a minimal repro: ``` set -eux rm -rf repro mkdir repro cd repro SITEPACK=env/site-packages mkdir -p $SITEPACK mkdir $SITEPACK/ruamel mkdir $SITEPACK/ruamel/yaml printf 'from ruamel.yaml.main import *' > $SITEPACK/ruamel/yaml/__init__.py printf 'import ruamel.yaml' > $SITEPACK/ruamel/yaml/main.py printf '' > $SITEPACK/ruamel/yaml/py.typed printf 'import ruamel.yaml' > a.py printf 'import a' > main.py rm -rf .mypy_cache PYTHONPATH=$SITEPACK mypy main.py PYTHONPATH=$SITEPACK mypy main.py ```
1 parent 60f00f3 commit cadecd6

File tree

2 files changed

+0
-12
lines changed

2 files changed

+0
-12
lines changed

mypy/semanal.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,6 @@ class SemanticAnalyzer(
404404
cur_mod_id = "" # Current module id (or None) (phase 2)
405405
_is_stub_file = False # Are we analyzing a stub file?
406406
_is_typeshed_stub_file = False # Are we analyzing a typeshed stub file?
407-
imports: set[str] # Imported modules (during phase 2 analysis)
408-
# Note: some imports (and therefore dependencies) might
409-
# not be found in phase 1, for example due to * imports.
410407
errors: Errors # Keeps track of generated errors
411408
plugin: Plugin # Mypy plugin for special casing of library features
412409
statement: Statement | None = None # Statement/definition being analyzed
@@ -445,7 +442,6 @@ def __init__(
445442
self.saved_locals: dict[
446443
FuncItem | GeneratorExpr | DictionaryComprehension, SymbolTable
447444
] = {}
448-
self.imports = set()
449445
self._type = None
450446
self.type_stack = []
451447
# Are the namespaces of classes being processed complete?
@@ -3114,9 +3110,6 @@ def visit_import_all(self, i: ImportAll) -> None:
31143110
# if '__all__' exists, all nodes not included have had module_public set to
31153111
# False, and we can skip checking '_' because it's been explicitly included.
31163112
if node.module_public and (not name.startswith("_") or "__all__" in m.names):
3117-
if isinstance(node.node, MypyFile):
3118-
# Star import of submodule from a package, add it as a dependency.
3119-
self.imports.add(node.node.fullname)
31203113
# `from x import *` always reexports symbols
31213114
self.add_imported_symbol(
31223115
name, node, context=i, module_public=True, module_hidden=False

mypy/semanal_main.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,6 @@ def semantic_analyze_target(
405405
)
406406
if isinstance(node, Decorator):
407407
infer_decorator_signature_if_simple(node, analyzer)
408-
for dep in analyzer.imports:
409-
state.add_dependency(dep)
410-
priority = mypy.build.PRI_LOW
411-
if priority <= state.priorities.get(dep, priority):
412-
state.priorities[dep] = priority
413408

414409
# Clear out some stale data to avoid memory leaks and astmerge
415410
# validity check confusion

0 commit comments

Comments
 (0)