Skip to content
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

Merged

Conversation

rbialon
Copy link
Contributor

@rbialon rbialon commented Oct 16, 2019

What do these changes do?

This PR introduces the get_extra_info() function on BaseRequest as suggested in #4189 .
It provides the same functionality as the current request.transport.get_extra_info() but is directly associated with request.

Are there changes in behavior for the user?

Users are encouraged to favor request.get_extra_info() instead of request.transport.get_extra_info(), as request.transport is about to be deprecated.

Related issue number

#4189

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .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.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

`BaseRequest.get_extra_info()` provides a shortcut for accessing extra
information from the underlying protocols' transport
@rbialon rbialon requested a review from asvetlov as a code owner October 16, 2019 13:11
@codecov-io
Copy link

codecov-io commented Oct 16, 2019

Codecov Report

Merging #4196 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
aiohttp/web_request.py 97.5% <100%> (+0.05%) ⬆️
aiohttp/web_fileresponse.py 96.59% <0%> (-1.71%) ⬇️
aiohttp/http_parser.py 96.88% <0%> (-0.23%) ⬇️
aiohttp/client_exceptions.py 100% <0%> (ø) ⬆️
aiohttp/typedefs.py 92.59% <0%> (+1.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6236536...771ad24. Read the comment docs.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 17, 2019
@rbialon rbialon requested a review from webknjaz as a code owner October 17, 2019 07:34
@rbialon rbialon changed the title WIP: Implement BaseRequest.get_extra_info() Implement BaseRequest.get_extra_info() Oct 17, 2019
@@ -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:
Copy link
Contributor Author

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?

Copy link
Member

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.
Copy link
Contributor Author

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
Copy link
Member

@asvetlov asvetlov left a 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

@asvetlov asvetlov merged commit fbc9cf6 into aio-libs:master Oct 18, 2019
@asvetlov
Copy link
Member

Thanks!

asvetlov pushed a commit that referenced this pull request Oct 18, 2019
* 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]>
@asvetlov
Copy link
Member

@rbialon if you want to help, #3882 is an easy issue that is similar to this one :)

asvetlov added a commit that referenced this pull request Oct 18, 2019
Add versionadded to get_extra_info() documentation
(cherry picked from commit fbc9cf6)

Co-authored-by: Raphael Bialon <[email protected]>
@rbialon
Copy link
Contributor Author

rbialon commented Oct 21, 2019

Thanks, I'll take a look at it :-)

@rbialon rbialon deleted the implement-baserequest-get_extra_info branch October 21, 2019 08:11
@asvetlov
Copy link
Member

Already done by #4240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants