Improve type annotations for several HTTPAdapter methods#15778
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
Collaborator
|
A general remark: We need a comment for each |
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Contributor
Author
|
I've addressed the review feedback: added explanatory comments for every Any usage in the stub file, including **pool_kwargs, **proxy_kwargs, return type of proxy_manager_for, **kwargs in add_headers, and the conn parameter in cert_verify. No functional changes, only type hint improvements. Please let me know if anything else is needed.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
improve type annotations for several HTTPAdapter methods
This PR improves the type hints for several methods in requests.adapters.HTTPAdapter to better reflect the actual runtime behavior and improve static type checking with tools such as mypy, pyright, and pylance.
The following methods now include more precise type annotations:
init_poolmanager
proxy_manager_for
add_headers
request_url
proxy_headers
These methods previously used untyped parameters or lacked explicit return types in the type stubs, which could lead to incomplete or inaccurate type inference in downstream projects.
Key improvements include:
Adding explicit parameter types (e.g. PreparedRequest, Mapping[str, str] | None)
Adding explicit return types such as None, str, and dict[str, str]
Using Any for flexible keyword arguments (**pool_kwargs, **proxy_kwargs, **kwargs) where the accepted parameters depend on urllib3 internals.
These changes do not modify runtime behavior and are strictly improvements to typing clarity and developer tooling support.