Skip to content

Require exact value types when validating Literal fields - #306

Closed
vitalivo wants to merge 1 commit into
konradhalas:masterfrom
vitalivo:fix/literal-value-types
Closed

vitalivo wants to merge 1 commit into
konradhalas:masterfrom
vitalivo:fix/literal-value-types

Conversation

@vitalivo

Copy link
Copy Markdown

Literal fields currently accept equal values of different types: Literal[1] accepts True, 1.0, and an IntEnum member whose value is 1; Literal[True] accepts the integer 1.

Require both matching types and equal values when validating a literal, as specified by PEP 586. Seven regression cases cover booleans, integers, floats, and integer enums, with correctly typed values as controls. Includes a changelog entry.

Validation: all seven regressions fail before the change; 210 tests pass on Python 3.10 and 3.13 (including the benchmark suite on 3.13). Black, mypy, and pylint checks pass. Pylint prints existing obsolete configuration warnings, identical to the base revision.

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.

1 participant