Skip to content
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

Fix error when assigning a ternary with an empty collection to a union type variable #7892

Merged
merged 2 commits into from Nov 7, 2019

Conversation

@TH3CHARLie
Copy link
Contributor

TH3CHARLie commented Nov 6, 2019

resolves #7780

Copy link
Collaborator

ilevkivskyi left a comment

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

mypy/checkexpr.py Outdated Show resolved Hide resolved
[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 {}

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Nov 6, 2019

Collaborator

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

This comment has been minimized.

Copy link
@TH3CHARLie

TH3CHARLie Nov 7, 2019

Author Contributor

Very reasonable to make it symmetric. See 47f9f25

test-data/unit/check-unions.test Outdated Show resolved Hide resolved
@ilevkivskyi ilevkivskyi merged commit 9ee7b8a into python:master Nov 7, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.