-
Notifications
You must be signed in to change notification settings - Fork 15
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
reorganize page_inputs.py as a submodule; move HttpClient to it #37
Conversation
web_poet/page_inputs/client.py
Outdated
_Body = Union[bytes, HttpRequestBody] | ||
|
||
|
||
async def _perform_request(request: HttpRequest) -> HttpResponse: |
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.
This needs to be inside this module, as moving it outside would cause a "circular import problem".
It's because _perform_request()
needs HttpRequest
and HttpResponse
from page_inputs for its annotations while HttpClient
(which is now inside the page_inputs subpackage) needs _perform_request()
.
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 think that can be possible to work around:
- add
from __future__ import annotations
to the module which contains _perform_request - add
if typing.TYPE_CHECKING: from web_poet... import HttpRequest, HttpResponse
See https://mypy.readthedocs.io/en/stable/runtime_troubles.html#import-cycles and https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking
On a first sight, having this function in client.py looks fine though :) Do you see a better location for this function?
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.
Hi @kmike , thanks for the suggestion! I was about to use your workaround but then simply importing HttpRequest
and HttpResponse
in requests.py is now working without the "circular import problem". I think the problem before was a bad ./tox
cache in my local machine. 😅
On a first sight, having this function in client.py looks fine though :) Do you see a better location for this function?
It would seem that the _perform_request()
function would be housed perfectly in web_poet/requests.py
. This makes web_poet/page_inputs/client.py
cleaner, containing code which emphasizes only on what users could use as page inputs.
Updated this in a4f1dcc.
Codecov Report
@@ Coverage Diff @@
## master #37 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 14 +3
Lines 285 289 +4
=========================================
+ Hits 285 289 +4
|
Thanks @BurnzZ! |
This adjusts the code after the said PR refactored the project structure. Reference: #37
Stemming off from #22 (comment).