8000 Allow isinstance/issubclass with nested tuples by pkch · Pull Request #2995 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Allow isinstance/issubclass with nested tuples #2995

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
merged 4 commits into from
Mar 18, 2017
Merged
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
Add reveal_type to test; remove tuple from test
  • Loading branch information
pkch committed Mar 18, 2017
commit f69ed43b404a6bc6288f3d838a3d9470a86e532d
11 changes: 8 additions & 3 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ z = [a.y for b in y for a in b]

[case testIsinstanceNestedTuple]
from typing import Union, List, Tuple, Dict
def f(x: Union[int, str, List, Tuple]) -> None:
if isinstance(x, (str, (int, tuple))):
x[1] # E: Value of type "Union[int, str, tuple]" is not indexable
def f(x: Union[int, str, List]) -> None:
if isinstance(x, (str, (int,))):
reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]'
x[1] # E: Value of type "Union[int, str]" is not indexable
else:
reveal_type(x) # E: Revealed type is 'builtins.list[Any]'
x[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add reveal_type(x) here.

reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]'
if isinstance(x, (str, (list,))):
Copy link
Collaborator

Choose a reason for hiding this comment

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

6046

Add reveal_type(x) before the if statement and within the if body.

reveal_type(x) # E: Revealed type is 'Union[builtins.str, builtins.list[Any]]'
x[1]
reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.list[Any]]'
[builtins fixtures/isinstancelist.pyi]

[case testClassAttributeInitialization-skip]
Expand Down
0