Repository navigation
Conversation
_create_norm_literal removed duplicates with a plain set, and True == 1, False == 0 and IntEnum/StrEnum members compare equal to their values, so Literal[1, True, None], Optional[Literal[1, True]] and Literal[0] | Literal[False] lost a case and rejected True/False under strict coercion. Dedup on (type, value) as _LiteralNormType.__eq__ does.
|
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.



When literals are merged (a
Literalinside a union, orNoneinside aLiteral),_create_norm_literalremoves duplicates with a plainset. SinceTrue == 1,False == 0and enum members compare equal to their values, one of them is dropped, and strict coercion then rejects it:This dedups on
(type, value)with the existing_type_and_value_iter, the same rule_LiteralNormType.__eq__and the strict literal loader already use. Real duplicates are still removed.One visible side effect: an enum member that equals a plain value, as in
Literal["red", Color.RED, None], is now kept, so it loads and dumps the wayLiteral["red", Color.RED]already does without the merge.Tests are added to
test_normalize_type.py::test_literalandtest_literal_provider.py; they fail ondevelop. The unit tests and ruff pass.Written with AI assistance (Claude); I have reviewed the change.