Skip to content

Require matching types when validating Literal values - #39

Merged
davidfstr merged 1 commit into
davidfstr:mainfrom
bensynapse:fix-literal-value-types
Oct 13, 2026
Merged

davidfstr merged 1 commit into
davidfstr:mainfrom
bensynapse:fix-literal-value-types

Conversation

@bensynapse

Copy link
Copy Markdown
Contributor

I run Live Tennis API.

trycast(Literal[1], True) currently returns True, and Literal[1] also accepts 1.0 or an equal IntEnum member.
Literal matching now checks the runtime type before comparing values, following the typing specification.

The regressions cover these collisions across trycast, checkcast and isassignable, including mixed Literals and a TypedDict field.
Ordinary numeric annotations keep their existing coercion rules.

Checked with poetry run make test, poetry run make lint, poetry build and the project tox environments on CPython 3.10 to 3.14.
The new tests produce 15 failing assertions against the original validator.

@davidfstr
davidfstr merged commit 8dec4cd into davidfstr:main Oct 13, 2026
5 checks passed
@davidfstr

Copy link
Copy Markdown
Owner

Changes look good, @bensynapse ! Thank you for your contribution.

Now I have a reason to work toward another trycast release...

@davidfstr davidfstr added this to the v2.0 milestone Oct 13, 2026
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.

2 participants