Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.3k
Namespace packages (PEP 420)#5691
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
586fc5a
Tentative solution for namespace packages
ecac1b5
Add tests for namespace packages
2da72cc
Add reveal_type() calls to tests
9d8f94d
Add test showing the first hit is used
de9049c
Add two tests for classic in namespace and vice versa -- both are BROKEN
201bf5f
Merge branch 'master' into namespaces
6ffd9b7
Correct typo in final test case
e65795f
Proper fix for nesting of namespace and classic packages
f1ac04a
Check that self.options isn't None
e36bdfe
Merge branch 'master' into namespaces
c91c9c1
Different way of handling nested classic/namespace packages; restore …
46b85d4
Update the comment, explaining the algorithm
bde1b0f
fix lint
644752a
Fix typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| -- Type checker test cases dealing with modules and imports. | ||
| -- Towards the end there are tests for PEP 420 (namespace packages, i.e. __init__.py-less packages). | ||
| [case testAccessImportedDefinitions] | ||
| import m | ||
| @@ -2525,3 +2526,97 @@ def __radd__(self) -> int: ... | ||
| [case testFunctionWithInPlaceDunderName] | ||
| def __iadd__(self) -> int: ... | ||
| -- Tests for PEP 420 namespace packages. | ||
| [case testClassicPackage] | ||
| from foo.bar import x | ||
| [file foo/__init__.py] | ||
| # empty | ||
| [file foo/bar.py] | ||
| x = 0 | ||
| [case testClassicNotPackage] | ||
| from foo.bar import x | ||
| [file foo/bar.py] | ||
| x = 0 | ||
| [out] | ||
| main:1: error: Cannot find module named 'foo.bar' | ||
| main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) | ||
| [case testNamespacePackage] | ||
| # flags: --namespace-packages | ||
| from foo.bar import x | ||
| reveal_type(x) # E: Revealed type is 'builtins.int' | ||
| [file foo/bar.py] | ||
| x = 0 | ||
| [case testNamespacePackageWithMypyPath] | ||
| # flags: --namespace-packages --config-file tmp/mypy.ini | ||
| from foo.bax import x | ||
| from foo.bay import y | ||
| from foo.baz import z | ||
| reveal_type(x) # E: Revealed type is 'builtins.int' | ||
| reveal_type(y) # E: Revealed type is 'builtins.int' | ||
| reveal_type(z) # E: Revealed type is 'builtins.int' | ||
| [file xx/foo/bax.py] | ||
| x = 0 | ||
| [file yy/foo/bay.py] | ||
| y = 0 | ||
| [file foo/baz.py] | ||
| z = 0 | ||
| [file mypy.ini] | ||
| [[mypy] | ||
| mypy_path = tmp/xx, tmp/yy | ||
gvanrossum marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [case testClassicPackageIgnoresEarlierNamespacePackage] | ||
| # flags: --namespace-packages --config-file tmp/mypy.ini | ||
| from foo.bar import y | ||
| reveal_type(y) # E: Revealed type is 'builtins.int' | ||
| [file xx/foo/bar.py] | ||
| x = '' | ||
| [file yy/foo/bar.py] | ||
| y = 0 | ||
| [file yy/foo/__init__.py] | ||
| [file mypy.ini] | ||
| [[mypy] | ||
| mypy_path = tmp/xx, tmp/yy | ||
| [case testNamespacePackagePickFirstOnMypyPath] | ||
| # flags: --namespace-packages --config-file tmp/mypy.ini | ||
| from foo.bar import x | ||
| reveal_type(x) # E: Revealed type is 'builtins.int' | ||
| [file xx/foo/bar.py] | ||
| x = 0 | ||
| [file yy/foo/bar.py] | ||
| x = '' | ||
| [file mypy.ini] | ||
| [[mypy] | ||
| mypy_path = tmp/xx, tmp/yy | ||
| [case testNamespacePackageInsideClassicPackage] | ||
| # flags: --namespace-packages --config-file tmp/mypy.ini | ||
| from foo.bar.baz import x | ||
| reveal_type(x) # E: Revealed type is 'builtins.int' | ||
| [file xx/foo/bar/baz.py] | ||
| x = '' | ||
| [file yy/foo/bar/baz.py] | ||
| x = 0 | ||
| [file yy/foo/__init__.py] | ||
| [file mypy.ini] | ||
| [[mypy] | ||
| mypy_path = tmp/xx, tmp/yy | ||
| [case testClassicPackageInsideNamespacePackage] | ||
| # flags: --namespace-packages --config-file tmp/mypy.ini | ||
| from foo.bar.baz.boo import x | ||
| reveal_type(x) # E: Revealed type is 'builtins.int' | ||
| [file xx/foo/bar/baz/boo.py] | ||
| x = '' | ||
| [file xx/foo/bar/baz/__init__.py] | ||
| [file yy/foo/bar/baz/boo.py] | ||
| x = 0 | ||
| [file yy/foo/bar/__init__.py] | ||
| [file mypy.ini] | ||
| [[mypy] | ||
| mypy_path = tmp/xx, tmp/yy | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.