Skip to content

Fix regression: list of enum literal tuples not accepted as Sequence of literal tuple union - #22521

Closed
zhengdaodeguL wants to merge 1 commit into
python:masterfrom
zhengdaodeguL:fix/literal-tuple-sequence-22514
Closed

zhengdaodeguL wants to merge 1 commit into
python:masterfrom
zhengdaodeguL:fix/literal-tuple-sequence-22514

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

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 to tuple[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 testLiteralEnumTupleUnionInSequenceContext to check-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). Full testcheck suite not run, left to CI.

…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.
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

[regression] List of enumerator literal tuples not accepted as argument with Sequence parameter

2 participants