feat: annotate HttpRequest as readable, HttpResponse as writable#3218
feat: annotate HttpRequest as readable, HttpResponse as writable#3218alexei wants to merge 1 commit intotypeddjango:masterfrom
Conversation
sobolevn
left a comment
There was a problem hiding this comment.
you don't have to inherit from a protocol to make use of it. HttpRequest already should be compatible with Readable and HttpResponse should be compatible with Writable.
If you want, you can submit a test case for that.
|
It's my fault for not explaining this. I found this while writing to a response with a function that accepted a writable file-thing i.e. |
|
@runtime_checkable
class Reader(Protocol[T_co]):
"""Protocol for simple I/O reader instances.
This protocol only supports blocking I/O.
"""
__slots__ = ()
@abc.abstractmethod
def read(self, size: int = ..., /) -> T_co:
"""Read data from the input stream and return it.
If *size* is specified, at most *size* items (bytes/characters) will be
read.
"""So, you don't need to modify django-stubs/django-stubs/http/request.pyi Line 117 in ca4389e Reader protocol.
As I said before you can add a test case to to_read: Reader = HttpRequest()And the same for |
HttpRequests are readable, whileHttpResponses are writable. It's insufficient that they havereadandwritemethods respectively, as one would have to use aProtocol. HoweverReaderandWriterare already available in theiopackage and are better suited.