Skip to content

requests.help static typing improvements#7506

Open
jorenham wants to merge 1 commit into
psf:mainfrom
jorenham:typing/help/coverage
Open

requests.help static typing improvements#7506
jorenham wants to merge 1 commit into
psf:mainfrom
jorenham:typing/help/coverage

Conversation

@jorenham

@jorenham jorenham commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Static type-checkers aren't very good at dealing with try/except blocks. Mypy, for example, reported 5 type errors in help.py because of this.

By moving these optional imports into an if TYPE_CHECKING block, static type-checkers will know how to deal with them. Even if these imports aren't found (because they're not installed), they'll be treated as Any, which won't lead to any typing issues (according to the gradual guarantee).

This also fixed another mypy error (related to mypy's greedy dict value type inference) by adding an inline annotation.

The final score is -6 mypy errors (0 left in help.py), and +1.02% type coverage (according to pyrefly report) for a grand total of 99.30% type coverage (roughly speaking that's the number of things that are typed / the number of things that can be typed).

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