Refactor ClientRequest
Goals
- Separate logic between the proxy version and the main version, which have different requirements. This reduces need for asserts etc. where we know an attribute will not be None in one case, but not the other. The proxy code now uses the internal ClientRequestBase, while ClientRequest is for the main request and will be exposed to middlewares.
- Rename some attributes/methods to better reflect what middleware users should be accessing (and matching what we've actually documented).
- Ensure body is always Payload (it was only not when None was passed previously), and strip out the redundant code that tries to send an empty body.
- Make it easier to make additions to ClientRequest in future releases without breaking subclasses.
TODO
If we're happy with this generally, then I still need to fix up the tests, which will take a substantial amount of work.
Codecov Report
:x: Patch coverage is 99.82993% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 98.73%. Comparing base (149a810) to head (740a95f).
:warning: Report is 67 commits behind head on master.
:white_check_mark: All tests successful. No failed tests found.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| aiohttp/connector.py | 90.90% | 0 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #11012 +/- ##
==========================================
- Coverage 98.74% 98.73% -0.02%
==========================================
Files 127 127
Lines 43535 43558 +23
Branches 2327 2320 -7
==========================================
+ Hits 42989 43007 +18
Misses 390 390
- Partials 156 161 +5
| Flag | Coverage Δ | |
|---|---|---|
| CI-GHA | 98.60% <98.97%> (-0.03%) |
:arrow_down: |
| OS-Linux | 98.34% <98.63%> (-0.03%) |
:arrow_down: |
| OS-Windows | 96.67% <98.63%> (-0.02%) |
:arrow_down: |
| OS-macOS | 97.56% <98.63%> (-0.03%) |
:arrow_down: |
| Py-3.10.11 | 97.11% <96.42%> (-0.05%) |
:arrow_down: |
| Py-3.10.18 | 97.60% <96.08%> (-0.05%) |
:arrow_down: |
| Py-3.11.13 | 97.80% <96.93%> (-0.04%) |
:arrow_down: |
| Py-3.11.9 | 97.32% <97.27%> (-0.03%) |
:arrow_down: |
| Py-3.12.10 | 97.42% <97.44%> (-0.04%) |
:arrow_down: |
| Py-3.12.11 | 97.92% <97.10%> (-0.03%) |
:arrow_down: |
| Py-3.13.7 | 97.92% <97.10%> (-0.29%) |
:arrow_down: |
| Py-3.13.8 | 97.14% <97.10%> (?) |
|
| Py-3.13.9 | 96.25% <97.10%> (?) |
|
| Py-3.14.0 | 98.12% <97.35%> (-0.05%) |
:arrow_down: |
| Py-3.14.0t | 97.19% <97.00%> (-0.04%) |
:arrow_down: |
| Py-pypy3.10.16-7.3.19 | 95.20% <95.91%> (+1.37%) |
:arrow_up: |
| VM-macos | 97.56% <98.63%> (-0.03%) |
:arrow_down: |
| VM-ubuntu | 98.34% <98.63%> (-0.03%) |
:arrow_down: |
| VM-windows | 96.67% <98.63%> (-0.02%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
CodSpeed Performance Report
Merging #11012 will not alter performance
Comparing clientrequest-refactor (740a95f) with master (1569ad9)[^unexpected-base]
[^unexpected-base]: No successful run was found on master (6a2809d) during the generation of this report, so 1569ad9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.
Summary
✅ 59 untouched
Sorry about the conflicts
Down to one perf regression
I changed RequestInfo to lazy construction. That should take care of the other one. Since they already have to adjust subclassing for ClientRequest we might as well do it now and they can adjust ClientResponse at the same time if they have swallowed some of the args.