Skip to content
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

modulefinder: make -p handle namespace packages correctly #9616

Merged
merged 4 commits into from
Oct 24, 2020
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
8 changes: 4 additions & 4 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,13 @@ def find_modules_recursive(self, module: str) -> List[BuildSource]:
if mod not in hits:
hits.add(mod)
result += self.find_modules_recursive(module + '.' + mod)
elif os.path.isdir(module_path) and module in self.ns_packages:
# Even more subtler: handle recursive decent into PEP 420
elif os.path.isdir(module_path):
# Even subtler: handle recursive decent into PEP 420
# namespace packages that are explicitly listed on the command
# line with -p/--packages.
for item in sorted(self.fscache.listdir(module_path)):
if os.path.isdir(os.path.join(module_path, item)):
result += self.find_modules_recursive(module + '.' + item)
item, _ = os.path.splitext(item)
result += self.find_modules_recursive(module + '.' + item)
return result


Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,17 @@ def bar(a: int, b: int) -> str:
[out]
src/anamespace/foo/bar.py:2: error: Incompatible return value type (got "int", expected "str")

[case testNestedPEP420Packages]
# cmd: mypy -p bottles --namespace-packages
[file bottles/jars/secret/glitter.py]
x = 0 # type: str
[file bottles/jars/sprinkle.py]
from bottles.jars.secret.glitter import x
x + 1
[out]
bottles/jars/secret/glitter.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
bottles/jars/sprinkle.py:2: error: Unsupported operand types for + ("str" and "int")

[case testFollowImportStubs1]
# cmd: mypy main.py
[file mypy.ini]
Expand Down