Abstract the public-facing API away from ClientResponse#13152
Abstract the public-facing API away from ClientResponse#13152Moist-Cat wants to merge 7 commits into
Conversation
It's important to notice that the __init__ method varies between
implementations and there are some leftovers (e.g, the _in_context field).
The base class is basically an interface.
for more information, see https://pre-commit.ci
Merging this PR will not alter performance
Comparing Footnotes
|
The CI complained but unit tests did not fail.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #13152 +/- ##
==========================================
- Coverage 98.97% 98.95% -0.02%
==========================================
Files 131 132 +1
Lines 48824 48857 +33
Branches 2546 2545 -1
==========================================
+ Hits 48324 48348 +24
- Misses 376 385 +9
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
| import contextlib | ||
| import json | ||
| from http.cookies import SimpleCookie | ||
| from typing import Any, Callable, Optional, Tuple |
There was a problem hiding this comment.
Callable, Optional, and Tuple are all deprecated.
| self._in_context = False | ||
| self._released: bool = False | ||
| self._resolve_charset: Callable[[Any, bytes], str] = lambda *_: "utf-8" |
There was a problem hiding this comment.
The subclass doesn't call this. These could just be class defaults anyway, so don't need the init to define them.
| self._resolve_charset: Callable[[Any, bytes], str] = lambda *_: "utf-8" | ||
|
|
||
| # ---------------------------------------------------------------- | ||
| # Abstract / overridable protocol methods |
There was a problem hiding this comment.
We probably want to ensure these are defined, right? In which case this should probably be an abstract class and these methods can all be defined as abstract.
| def headers(self) -> Any: | ||
| return self._headers | ||
|
|
||
| @property | ||
| def history(self) -> Tuple[Any, ...]: |
There was a problem hiding this comment.
Seem to have lost typing information that we had before?
|
|
||
|
|
||
| class ClientResponse(HeadersMixin): | ||
| class ClientResponse(BaseResponse): |
There was a problem hiding this comment.
So this is the HTTP/1 class, right?
I still think, atleast in master/v4, that we probably want to rename this and have the base class be called ClientResponse. That means that middlewares etc. which reference ClientResponse shouldn't need any changes to work in future with the HTTP/2 class.
With these current changes, we'd need to changes lots of references from ClientResponse -> BaseResponse, both in our code and in user's code.
It's important to notice that the
__init__method varies between implementations and there are some extra fields (e.g, the _in_context field) that are required by some methods used outside the class.The base class is basically an interface that implements the public API. Fields can't be stored in the base class because they may or may not be available during
__init__so I'm thinking of removing the constructor altogether.Related PR
#13039