Skip to content

types: fix variance issues and improve type coverage#3450

Merged
Rowlando13 merged 2 commits into
pallets:stablefrom
jorenham:typing/types/variance-fixes-and-type-coverage
May 30, 2026
Merged

types: fix variance issues and improve type coverage#3450
Rowlando13 merged 2 commits into
pallets:stablefrom
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.

@kdeldycke kdeldycke added this to the 8.4.2 milestone May 22, 2026
@kdeldycke kdeldycke changed the base branch from main to stable May 22, 2026 12:12
@jorenham jorenham force-pushed the typing/types/variance-fixes-and-type-coverage branch from 22ea58b to 0914020 Compare May 25, 2026 09:57
@jorenham jorenham force-pushed the typing/types/variance-fixes-and-type-coverage branch from 0914020 to 9a2d169 Compare May 25, 2026 09:59
@Rowlando13
Copy link
Copy Markdown
Collaborator

Rowlando13 commented May 30, 2026

I don't have enough knowledge of typing to review these changes. @kdeldycke

@kdeldycke
Copy link
Copy Markdown
Collaborator

I don't have enough knowledge of typing to review these changes. @kdeldycke

Same thing here, my brain breaks a bit with these kind of high-level typing. So no strong technical opinion on my side: the tests pass, the type checker is happy, the code does not introduce any malware, is purely type checking, and @jorenham already demonstrated reactivity and seriousness. So based on these circumstantial evidences, I would merge it and go ahead! Let's clear the backlog! 🤠

@Rowlando13 Rowlando13 merged commit 65feb61 into pallets:stable May 30, 2026
12 checks passed
@jorenham jorenham deleted the typing/types/variance-fixes-and-type-coverage branch May 30, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants