Closed drderuiter closed 3 years ago
Merging #15 (c92437c) into main (324c9b0) will decrease coverage by
0.09%
. The diff coverage is93.33%
.
@@ Coverage Diff @@
## main #15 +/- ##
==========================================
- Coverage 92.82% 92.73% -0.10%
==========================================
Files 11 11
Lines 683 688 +5
==========================================
+ Hits 634 638 +4
- Misses 49 50 +1
Impacted Files | Coverage Δ | |
---|---|---|
aiohttp_pydantic/view.py | 97.14% <93.33%> (-1.32%) |
:arrow_down: |
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 324c9b0...c92437c. Read the comment docs.
I'm afraid that the better way to increase the interoperability whit other tools is to provide a class inherited from object - a mixin - designed to be combined with web.View
or subclasses of web.View
aiohttp-pydantic can provide.
PydanticMixin
and PydanticView
where PydanticView
will be defined as:
class PydanticView(PydanticMixin, web.View):
...
If the user need to use aiohttp-pydantic with existing View it can do:
class MyExistingViewWithPydantic(PydanticMixin, MyExistingView):
...
Merged with https://github.com/Maillol/aiohttp-pydantic/pull/16 after refactoring
The changes in this PR make
PydanticView
structurally a subclass of theaiohttp.web.View
. It should make it easier to usePydanticView
in places where a regularView
is expected. The changes also allow one to inherit from aPydanticView
.Rationale
I was working with
aiohttp_pydantic
in combination with some other tool, which are designed to work with a regularView
. The tool assumed that for non-allowed methods, the handler attribute was missing. This is not the case for the currentPydanticView
, which sets theraise_not_allowed
handler for such methods.The tool would also subclass the
View
, which does not work for anPydanticView
. Upon subclassing:Implementation
aiohttp.web.View
. This solves part of the inheritance problem, as no methods are attached for non-allowed methods.PydanticView
base class.Alternative solutions
For the inheritance problem, another solution could be to just raise a warning when a subclass of
PydanticView
is subclassed again. That does not solve the problem, but will let users know that this was not the intended usage.Curious to hear your thoughts. I'm aware that this is a breaking change as it changes the public interface, but the added compatibility with regular the
View
should be useful.