#30755: Have django.views.generic.base.View.as_view() check argument type, via
annotations.
-------------------------------+-----------------------------------------
Reporter: David Szotten | Owner: nobody
Type: New feature | Status: closed
Component: Generic views | Version: master
Severity: Normal | Resolution: needsinfo
Keywords: typing | Triage Stage: Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Comment (by David Szotten):
I'm happy to leave this to the linked mailing list discussion/dep
In the mean time, would you accept a patch pulling out the `initkwargs`
validation from `as_view` into a helper method, to make it easier for me
to override this behaviour in my projects?
Are you able to confirm that the only use-case for the validation is to
catch likely mistakes/typos? Not to diminish it, i think it's very
valuable, but i'm trying to make sure I'm not breaking something if i
override this behaviour. (In a type-annotated codebase I think a type
annotation is an equally valid "statement of intent")
For some more context,
the reason I'd rather not make it `Optional` is that it isn't really and
I'd like the type checker to know that this value is always say a `str`
and not make me check for `None`.
{{{
class MyView(View):
key: str
def get(self, request):
# at this point self.key is definitely a str, not an Optional[str]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30755#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.c58249498f4e0089cde2dab1906b8750%40djangoproject.com.