Open
Description
Bug report
What's wrong
Getting an error on a reasonable line in my test suite involving a StreamingHttpResponse.streaming_content
in vscode / pylance and mypy.
As long as the type is identified by the type checker it will emit the error, stick this anywhere:
from django.http import StreamingHttpResponse
g = (str(x).encode() for x in range(100)) # does not even matter if this is real....
response = StreamingHttpResponse(g, status_code=200)
content = b"".join(response.streaming_content) # <- mypy/pylance error
The code iterates over it just fine, the join returns bytes.
mypy emits:
error: Argument 1 to "join" of "bytes" has incompatible type "Iterator[bytes] | AsyncIterator[bytes]"; expected "Iterable[Buffer]" [arg-type]
in VSCode the Pylance popup states
Argument of type "Iterable[object] | AsyncIterable[object]" cannot be assigned to parameter "iterable_of_bytes" of type "Iterable[ReadableBuffer]" in function "join"
Type "Iterable[object] | AsyncIterable[object]" is not assignable to type "Iterable[ReadableBuffer]"
"AsyncIterable[object]" is incompatible with protocol "Iterable[ReadableBuffer]"
"__iter__" is not presentPylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
(variable) streaming_content: Iterable[object] | AsyncIterable[object]
What would be correct
No type warning/error in the type checker there.
(Maybe I'm missing something subtle about typing, but imo that code should pass type inspection.)
It seems likely that swapping bytes
for buffer
/Buffer
fixes this, but I'm nowhere near fluent enough with this stuff to proceed further. The detail with async being incompatible seems like a different problem, but again, this just is not at my level.
System information
- OS:
python
version: 3.12.xdjango
version: 4.2.21mypy
version: 1.15.0django-stubs
version: 5.2.0django-stubs-ext
version: 5.2.0
Testing on the most recent version of pylance included with vscode, not the beta.