8000 Expand imports in classes by A5rocks · Pull Request #11344 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Expand imports in classes #11344

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

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test cases
  • Loading branch information
A5rocks committed Oct 16, 2021
commit 35d475dc60477d6015b6f8c4ba15f14f599b80c9
23 changes: 21 additions & 2 deletions test-data/unit/check-classes.test
< 8000 /div>
Original file line number Diff line number Diff line change
Expand Up @@ -6925,8 +6925,13 @@ def meth(self, x: int) -> int:
class Foo:
from not_a_module import func

reveal_type(Foo.func) # N: Revealed type is "Any"
reveal_type(Foo().func) # N: Revealed type is "Any"
reveal_type(Foo.func)
reveal_type(Foo().func)
[out]
main:2: error: Cannot find implementation or library stub for module named "not_a_module"
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:4: note: Revealed type is "Any"
main:5: note: Revealed type is "Any"

[case testExpandImportedMethodWithFollowImports]
# flags: --follow-imports=skip
Expand All @@ -6937,3 +6942,17 @@ reveal_type(Foo().meth) # N: Revealed type is "Any"
[file a.py]
def meth(self, x: int) -> int:
...

[case testExpandWithNonSelfFirstArgument]
class Foo:
from a import func

reveal_type(Foo().func)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test what happens if we import two functions with the same name (from 5B92 different modules)?

Also test what happens if we import a function over an existing name.

Test multiple classes that import the same function.

Test calling the original function via module and instance.

reveal_type(Foo.func)
[file a.py]
def func(self: str, x: int) -> int:
...
[out]
main:4: error: Invalid self argument "Foo" to attribute function "func" with type "Callable[[str, int], int]"
main:4: note: Revealed type is "def (x: builtins.int) -> builtins.int"
main:5: note: Revealed type is "def (self: builtins.str, x: builtins.int) -> builtins.int"
0