Skip to content

Support indexing unions containing tuples #6475

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 2 commits into from
Feb 26, 2019

Conversation

ilevkivskyi
Copy link
Member

Fixes #4286
Fixes #2509

The fix is straightforward, map the indexing through union types. I decided to use the existing error message mentioning the full type. IMO Value of type "Union[int, List[int]]" is not indexable is better than Value of type "int" is not idexable.

Copy link
Collaborator

@Michael0x2a Michael0x2a left a comment

Choose a reason for hiding this comment

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

I left one small question, but apart from that LGTM!

"""
index = e.index
if isinstance(left_type, UnionType):
return UnionType.make_simplified_union([self.visit_index_with_type(typ, e, left_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to check, should we pass original_type here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Normally, there should be no nested unions because they are flattened in the constructor, but I agree that it would be more robust to pass it also here.

@ilevkivskyi ilevkivskyi merged commit 69eaf88 into python:master Feb 26, 2019
@ilevkivskyi ilevkivskyi deleted the union-ops branch February 26, 2019 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants