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

Simplify unions when erasing last known values #12064

Merged
merged 4 commits into from
Jan 25, 2022
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 25, 2022

When we erase last known values in an union with multiple
Instance types, make sure that the resulting union doesn't have
duplicate erased types. The duplicate items weren't incorrect as such,
but they could cause overly complex error messages and potentially
slow type checking performance.

This is one of the fixes extracted from #12054. Since some of the
changes may cause regressions, it's better to split the PR.

Work on #12051.

A few bugs in type operations were exposed by #11962. This fixes
them.

Fix #12051, but other use cases are affected as well.

First, when we erase last known values in an union with multiple
Instance types, make sure that the resulting union doesn't have
duplicate erased types. The duplicate items weren't incorrect as such,
but they could cause overly complex error messages and potentially
slow type checking performance.

Second, make the join of a union type and Any commutative.
Previously the result dependend on the order of the operands,
which was clearly incorrect.
@github-actions

This comment has been minimized.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 25, 2022

This seems to have some unintended consequences. I'm going to try making the union simplification less eager.

@JukkaL JukkaL requested a review from sobolevn January 25, 2022 14:00
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 25, 2022

@sobolevn This is similar to the first half of #12054, but this only simplifies in the cases that we care about to avoid changes in external behavior. Using make_simplified_union always was a too big and unnecessary change. It would be great if you can have another look.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks, I start to understand what is going on with this bug 🙂

mypy/test/typefixture.py Outdated Show resolved Hide resolved
Co-authored-by: Nikita Sobolev <[email protected]>
@JukkaL JukkaL merged commit 3680449 into master Jan 25, 2022
@JukkaL JukkaL deleted the fix-literal-union branch January 25, 2022 15:08
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.

2 participants