asgi.App should not be a sub-class of falcon.App #2210
davetapley
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
Hi, Please take a look at #2211 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I don't follow, you can surely create a type guard to accept only a subclass. What you can't do is the inverse, you can't create a type guard for the superclass |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is motivated by #2209 (comment), TLDR:
Because an
asgi.App
is (in the LSP sense) afalcon.App
,any type for a
falcon.App
must be 'polluted' with types which only make sense in the ASGI context. E.g.:The
simulate_request
methods intesting.client
must returnResult | StreamedResult
,even though it's not possible to get a
StreamedResult
with WSGI (akafalcon.App
).That's awkward because
StreamedResult
doesn't have the very usefultext
andjson
methods.I would like to propose moving the shared functionality out of
falcon.App
and in to a mix-in class.Then methods like ⬇️ could be extended with a
TypeGuard
.falcon/falcon/testing/client.py
Line 2177 in 4910dd7
and it will be possible to use
@overload
to correctly narrow to justResult
.I suspect there are other places in the code which would benefit from this (e.g. all the ASGI only websocket code).
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions