KEMBAR78
Fix error when assigning a ternary with an empty collection to a union type variable by TH3CHARLie · Pull Request #7892 · python/mypy · GitHub
Skip to content

Conversation

TH3CHARLie
Copy link
Collaborator

resolves #7780

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks, the general idea looks good. I have few suggestions.

[case testAssignUnionWithTenaryExprWithEmptyCollection]
from typing import Dict, List, Union
x: Union[int, List[int]] = 1 if "" else []
y: Union[int, Dict[int, int]] = 1 if "" else {}
Copy link
Member

Choose a reason for hiding this comment

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

Could you please also add the opposite conditional expressions to the test (since the current inference logic seems to be a bit asymmetric):

x: Union[int, List[int]] = [] if bool() else 1
y: Union[int, Dict[int, int]] = {} if bool() else 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very reasonable to make it symmetric. See 47f9f25

@ilevkivskyi ilevkivskyi merged commit 9ee7b8a into python:master Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when assigning a ternary with an empty collection to a union type variable

2 participants