Remove obsolete Literal deduplication assertion - #785
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #785 +/- ##
==========================================
- Coverage 97.26% 97.26% -0.01%
==========================================
Files 3 3
Lines 7860 7859 -1
==========================================
- Hits 7645 7644 -1
Misses 215 215
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
AlexWaygood
marked this pull request as ready for review
August 12, 2026 11:56
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 #784.
Summary
Remove the assertion that
Literal[[], []].__args__is([], []). python/cpython#153914 deliberately changedtyping.Literalto deduplicate unhashable arguments, so Python 3.14.7 now returns([],)instead. On supported Python versions wheretyping_extensions.Literalaliasestyping.Literal, the old assertion therefore contradicts the standard library behavior.This PR just deletes the assertion entirely: the behaviour here is now version-dependent, and the assertion was always testing an implementation detail that wasn't really that important.
Historical context
typing_extensionsin Fix various things withLiteral#145. That PR addressed (🐞)Literaldoesn't flatten it's arguments #113 and backported bpo-42345: Fix three issues with typing.Literal parameters cpython#23294 and bpo-42345: Fix hash implementation of typing.Literal cpython#23383. The assertion was copied verbatim with the rest of CPython'sLiteralTests.test_argsin the first commit of that PR. There was no discussion about this particular assertion on Fix various things withLiteral#145.Union, and Guido asked whether mutableLiteralarguments were actually valid.Literalarguments at type-checking time but intentionally does not validate them at runtime. The CPython reviewers therefore agreed not to deduplicate mutable arguments. Guido subsequently requested explicit__args__coverage, and commit f653d680 introduced the exact assertion that Fix various things withLiteral#145 later copied.typing_extensionsimplementation bug.