#33683: Document HttpResponseBase and allow import from django.http
--------------------------------------+------------------------------------
Reporter: Collin Anderson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Carlton Gibson):
Hey Colin.
There's a PEP here: [https://peps.python.org/pep-0544/ PEP 544 –
Protocols: Structural Subtyping (Static Duck Typing)]
The idea roughly being that you declare a protocol, which any class can
conform to, and use that in your annotations, rather than requiring a
specific subclass, since folks are used to passing any kind of object that
responds appropriately.
> Does Python typing allow... erm... retrofitting — that's probably not
the word — protocol conformance? 🤔
Reading from the PEP, on [https://peps.python.org/pep-0544/#explicitly-
declaring-implementation Explicitly declaring implementation]:
> Static analysis tools are expected to automatically detect that a class
implements a given protocol. So while it’s possible to subclass a protocol
explicitly, it’s not necessary to do so for the sake of type-checking.
So... testing needed but... one would hope that a suitable Protocol
definition would satisfy the type-checkers, without needing changes
everywhere in the existing code.
With `runtime_checkable()` it looks like that's usable with `isinstance()`
too which might help avoid issues like #33362.
None of this is necessary here — more just thinking how we move forward:
documenting `HttpResponseBase` is fine I think.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/33683#comment:4>
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/01070180acb7f703-90c90ef2-a351-4a32-a4dd-765ae6461e8a-000000%40eu-central-1.amazonses.com.