-
-
Notifications
You must be signed in to change notification settings - Fork 939
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
Liskov substitution problems in new Response.render
type signature
#2242
Comments
Thanks @salotz, mypy didn't catch this as |
I'm fine with reverting the |
I agree I only started writing types this year. The promise of "gradual typing" seems nice but in practice I've found that you should either start a project with |
I also agree with @Kludex, I will do a simple PR to revert it, feel free to close it if we decide to implement the generic types |
I recently updated to 0.31.0 and found I had a new type checking error (I run with
mypy --strict
).This is due to the base class
Response
having the type signature forrender
being constrained tostr | bytes | None
. From this PR: #2183 @Viicos @KludexHere is my derived class using starlette 0.28.0:
Now I could put the encoding from my arbitrary Python object
Model
into the application code, but I quite like it being part of the response. In any case this is how it is advertised in the documentation and indeed the derived classJSONResponse
in that same module re-types it toAny
: https://github.com/encode/starlette/blob/master/starlette/responses.py#L180.Whatever the final decision is I think this contradiction needs to be clarified.
Possible solutions would be (in order of preference):
Response.render
type signature to acceptAny
(Any is typically the wrong solution for most issues and especially this, but it at least works with subtyping to more specific types)And my class could be:
Important
The text was updated successfully, but these errors were encountered: