Skip to content

types: fix variance issues and improve type coverage#3450

Open
jorenham wants to merge 2 commits into
pallets:mainfrom
jorenham:typing/types/variance-fixes-and-type-coverage
Open

types: fix variance issues and improve type coverage#3450
jorenham wants to merge 2 commits into
pallets:mainfrom
jorenham:typing/types/variance-fixes-and-type-coverage

Conversation

@jorenham
Copy link
Copy Markdown
Contributor

@jorenham jorenham commented May 18, 2026

The generic types in click.types were all parametrized using an invariant type parameter. This can easily lead to unexpected type errors for downstream users. For example, type-checkers would not allow you to assign ParamType[bool] to an ParamType[int], even though bool is a subclass of int. This addresses these issues by using appropriate variance for these generic type parameters.

This also fixes several other typing issues, removing several # type: ignores and t,casts.

I also took the parametrize some of the typed dicts, avoid several (intrinsically type-unsafe) Any annotations.

And just like #3422, this also fills in the missing annotations of attributes and constants. This consequently increases the type coverage by 2.18% (91.5% -> 93.68%).

I realize there are quite a lot of changes here. But I was afraid that spreading these out over multiple PRs would result in a merge conflict mess. But if you want me to split this up anyway, then that's also fine as far as I'm concerned.

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