Repository navigation
Fix regression: list of enum literal tuples not accepted as Sequence of literal tuple union - #22521
Closed
zhengdaodeguL wants to merge 1 commit into
Closed
zhengdaodeguL wants to merge 1 commit into
zhengdaodeguL wants to merge 1 commit into
Conversation
…of literal tuple union Fixes python#22514 In solve_one(), the inferred lower bound was accepted when it was a subtype of the upper bound only via temporary literal 'last known values' on enum instances. Those values are erased after inference, widening the list element type to tuple[Color, Shape], which does not satisfy the literal tuple union. Check the subtype relation against the lower bound with last known values removed, so the unstable solution is rejected and inference falls back to the contextual literal union.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22514
In
solve_one(), the inferred lower bound was accepted when it was a subtype of the upper bound only via temporary literal "last known values" on enum instances. Those values are erased after inference, widening the list element type totuple[Color, Shape], which does not satisfy the literal tuple union.Fix: check the subtype relation against the lower bound with last known values removed (
remove_instance_last_known_values), so the unstable solution is rejected and inference falls back to the contextual literal union.Added
testLiteralEnumTupleUnionInSequenceContexttocheck-literal.test(the exact repro from the issue, plus 4 valid and 2 invalid combinations); it fails before this change and passes after. Related suites pass (testcheck.py -k literal: 224 passed, 2 skipped;-k solve: 6 passed;testsolve.py: 22 passed;testtypes.py: 122 passed, 2 skipped). Fulltestchecksuite not run, left to CI.