8000 Fix crash when a star expression is used in isinstance by onlined · Pull Request #6659 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix crash when a star expression is used in isinstance #6659

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 6 commits into from
Apr 12, 2019
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
Next Next commit
Improve tests
  • Loading branch information
onlined committed Apr 12, 2019
commit 80d7811923f19d6152e3a951c2c69cedd5cf282b
24 changes: 16 additions & 8 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -2209,17 +2209,25 @@ def bar(x: Union[List[str], List[int], None]) -> None:
[builtins fixtures/isinstancelist.pyi]

[case testIsInstanceWithStarExpression]
var = 'some string'
if isinstance(var, (list, *(str, int))):
reveal_type(var) # E: Revealed type is 'builtins.str'
from typing import Union, List, Tuple


def f(var: Union[List[str], Tuple[str, str], str]) -> None:
reveal_type(var) # E: Revealed type is 'Union[builtins.list[builtins.str], Tuple[builtins.str, builtins.str], builtins.str]'
if isinstance(var, (list, *(str, int))):
reveal_type(var) # E: Revealed type is 'Union[builtins.list[builtins.str], builtins.str]'
[builtins fixtures/isinstancelist.pyi]

[case testIsInstanceWithStarExpressionAndVariable]
some_types = (str, tuple)
another_type = list
var = 'some string'
if isinstance(var, (*some_types, another_type)):
reveal_type(var) # E: Revealed type is 'builtins.str'
from typing import Union


def f(var: Union[int, str]) -> None:
reveal_type(var) # E: Revealed type is 'Union[builtins.int, builtins.str]'
some_types = (str, tuple)
another_type = list
if isinstance(var, (*some_types, another_type)):
reveal_type(var) # E: Revealed type is 'builtins.str'
[builtins fixtures/isinstancelist.pyi]

[case testIsInstanceWithWrongStarExpression]
Expand Down
0