10270: add annotation to twisted.web.http.Request.getHeader#1669
Merged
twm merged 5 commits intotwisted:trunkfrom Feb 6, 2022
Merged
10270: add annotation to twisted.web.http.Request.getHeader#1669twm merged 5 commits intotwisted:trunkfrom
twisted.web.http.Request.getHeader#1669twm merged 5 commits intotwisted:trunkfrom
Conversation
twisted.web.http.Request.getHeadertwisted.web.http.Request.getHeader
clokep
reviewed
Oct 21, 2021
| # The following is the public interface that people should be | ||
| # writing to. | ||
| def getHeader(self, key): | ||
| def getHeader(self, key: AnyStr) -> Optional[AnyStr]: |
Contributor
There was a problem hiding this comment.
I think this might need overloads to successfully capture that the type of the output matches the type of the input. (A str key causes a Optional[str] return value.)
Contributor
Author
There was a problem hiding this comment.
AnyStr is a TypeVar, so I think this should be fine as is. See https://docs.python.org/3/library/typing.html?highlight=anystr#typing.AnyStr (and note the same is done in the definition of getRawHeaders().
Contributor
There was a problem hiding this comment.
Ah, I hadn't realized AnyStr didn't allow mixing. Seems perfect then! 👍
DMRobertson
pushed a commit
to matrix-org/sydent
that referenced
this pull request
Oct 21, 2021
Adding the stub for `getHeader` means that mypy isn't looking at twisted's implementation to deduce what types instance attributes have. So let's add those to the stub. I don't want to maintain a stub out-of-tree forever, but I've submitted the `getHeader` annotation upstream in twisted/twisted#1669 .
wsanchez
approved these changes
Jan 12, 2022
Member
|
Thank you all! |
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.
Scope and purpose
Another drive-by contribution. Similar to #1668.
Contributor Checklist:
tox -e lintto format my patch to meet the Twisted Coding Standard#character).readBodyas per the docstring #1668.reviewto the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.The first line is automatically generated by GitHub based on PR ID and branch name.
The other lines generated by GitHub should be replaced.