-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement BaseRequest.get_extra_info() #4196
Implement BaseRequest.get_extra_info() #4196
Conversation
`BaseRequest.get_extra_info()` provides a shortcut for accessing extra information from the underlying protocols' transport
Codecov Report
@@ Coverage Diff @@
## master #4196 +/- ##
==========================================
- Coverage 97.57% 97.53% -0.05%
==========================================
Files 43 43
Lines 8825 8837 +12
Branches 1381 1383 +2
==========================================
+ Hits 8611 8619 +8
- Misses 92 94 +2
- Partials 122 124 +2
Continue to review full report at Codecov.
|
@@ -673,6 +673,18 @@ def body_exists(self) -> bool: | |||
self._post = MultiDictProxy(out) | |||
return self._post | |||
|
|||
def get_extra_info(self, name: str, default: Any = None) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that I defined the name
parameter for get_extra_info
to be a string both in the documentation and type hinting.
This is true, but it could also be any other valid dictionary key. Should I reconsider this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in asyncio the key is a string by convention.
Reads extra information from the protocol's transport. | ||
If no value associated with ``name`` is found, ``default`` is returned. | ||
|
||
:param str name: The key to look up in the transport extra information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's defined as a string here, too.
Add versionadded to get_extra_info() documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI failure is unrelated, fixed on master already
Thanks! |
* Add get_extra_info for BaseRequest `BaseRequest.get_extra_info()` provides a shortcut for accessing extra information from the underlying protocols' transport * Add get_extra_info default value test * Add return type annotation to BaseRequest.get_extra_info() * Remove async from BaseRequest.get_extra_info() * Rewrite get_extra_info test, cover all branches * Add news entry to CHANGES for #4189 * Add Raphael Bialon to CONTRIBUTORS.txt * Add documentation for BaseRequest.get_extra_info() * Update web_reference.rst Add versionadded to get_extra_info() documentation (cherry picked from commit fbc9cf6) Co-authored-by: Raphael Bialon <[email protected]>
Add versionadded to get_extra_info() documentation (cherry picked from commit fbc9cf6) Co-authored-by: Raphael Bialon <[email protected]>
Thanks, I'll take a look at it :-) |
Already done by #4240 |
What do these changes do?
This PR introduces the
get_extra_info()
function onBaseRequest
as suggested in #4189 .It provides the same functionality as the current
request.transport.get_extra_info()
but is directly associated withrequest
.Are there changes in behavior for the user?
Users are encouraged to favor
request.get_extra_info()
instead ofrequest.transport.get_extra_info()
, asrequest.transport
is about to be deprecated.Related issue number
#4189
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.