Skip to content

Commit 7b8c58c

Browse files
committed
Get rid of all_are_submodules and add a test for a bug this fixes
1 parent 12b3982 commit 7b8c58c

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

mypy/build.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -692,23 +692,17 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
692692
elif isinstance(imp, ImportFrom):
693693
cur_id = correct_rel_imp(imp)
694694
pos = len(res)
695-
all_are_submodules = True
696695
# Also add any imported names that are submodules.
697696
pri = import_priority(imp, PRI_MED)
698697
for name, __ in imp.names:
699698
sub_id = cur_id + '.' + name
700699
if self.is_module(sub_id):
701700
res.append((pri, sub_id, imp.line))
702-
else:
703-
all_are_submodules = False
704-
# If all imported names are submodules, don't add
705-
# cur_id as a dependency. Otherwise (i.e., if at
706-
# least one imported name isn't a submodule)
707-
# cur_id is also a dependency, and we should
708-
# insert it *before* any submodules.
709-
if not all_are_submodules:
710-
pri = import_priority(imp, PRI_HIGH)
711-
res.insert(pos, ((pri, cur_id, imp.line)))
701+
# Add cur_id as a dependency, even if all of the
702+
# imports are submodules. Processing import from will try
703+
# to look through cur_id, so we should depend on it.
704+
pri = import_priority(imp, PRI_HIGH)
705+
res.insert(pos, ((pri, cur_id, imp.line)))
712706
elif isinstance(imp, ImportAll):
713707
pri = import_priority(imp, PRI_HIGH)
714708
res.append((pri, correct_rel_imp(imp), imp.line))

test-data/unit/check-incremental.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,3 +4265,20 @@ cache_fine_grained = False
42654265
cache_fine_grained = True
42664266
[rechecked a, builtins]
42674267
[stale a, builtins]
4268+
4269+
[case testIncrementalPackageNameOverload]
4270+
# cmd: mypy -m main a
4271+
# flags: --follow-imports=skip
4272+
[file main.py]
4273+
from a import x
4274+
x.foo()
4275+
[file a/__init__.py]
4276+
pass
4277+
[file a/__init__.py.2]
4278+
x = 10
4279+
[file a/x.py]
4280+
def foo() -> None:
4281+
pass
4282+
[out]
4283+
[out2]
4284+
tmp/main.py:2: error: "int" has no attribute "foo"

0 commit comments

Comments
 (0)