Skip to content
Myr

Refactor to use isinstance(..., typing.Iterator) (#1282)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 5ee6135 · Browse files · 1 file+4 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−8 removed

  • other:+4 added−8 removed

1 file+4 added−8 removed

modified:httpx/_content_streams.py+4 added-8 removed
378 unmodified lines
379 else:380 return URLEncodedStream(data=data)381 elif isinstance(data, (str, bytes)):382 return ByteStream(body=data)383 elif hasattr(data, "__aiter__"):384 data = typing.cast(typing.AsyncIterator[bytes], data)383 elif isinstance(data, typing.AsyncIterator):384 return AsyncIteratorStream(aiterator=data)386 elif hasattr(data, "__iter__"):387 data = typing.cast(typing.Iterator[bytes], data)385 elif isinstance(data, typing.Iterator):386 return IteratorStream(iterator=data)387388 raise TypeError(f"Unexpected type for 'data', {type(data)!r}")389
2 unmodified lines
392 if content is None:393 return ByteStream(b"")394 elif isinstance(content, bytes):395 return ByteStream(body=content)398 elif hasattr(content, "__aiter__"):399 content = typing.cast(typing.AsyncIterator[bytes], content)396 elif isinstance(content, typing.AsyncIterator):397 return AsyncIteratorStream(aiterator=content)401 elif hasattr(content, "__iter__"):402 content = typing.cast(typing.Iterator[bytes], content)398 elif isinstance(content, typing.Iterator):399 return IteratorStream(iterator=content)400401 raise TypeError(f"Unexpected type for 'content', {type(content)!r}")