Skip to content

Commit

Permalink
Update type annotations to reflect behavior when null buffer is passe…
Browse files Browse the repository at this point in the history
…d to `write`
  • Loading branch information
zanieb committed Mar 25, 2022
1 parent d3b888b commit f9a9847
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion httpcore/backends/asyncio.py
Expand Up @@ -32,7 +32,7 @@ async def read(self, max_bytes: int, timeout: float = None) -> bytes:
except anyio.EndOfStream: # pragma: nocover
return b""

async def write(self, buffer: bytes, timeout: float = None) -> None:
async def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
if not buffer:
return

Expand Down
4 changes: 2 additions & 2 deletions httpcore/backends/base.py
Expand Up @@ -7,7 +7,7 @@ class NetworkStream:
def read(self, max_bytes: int, timeout: float = None) -> bytes:
raise NotImplementedError() # pragma: nocover

def write(self, buffer: bytes, timeout: float = None) -> None:
def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
raise NotImplementedError() # pragma: nocover

def close(self) -> None:
Expand Down Expand Up @@ -42,7 +42,7 @@ class AsyncNetworkStream:
async def read(self, max_bytes: int, timeout: float = None) -> bytes:
raise NotImplementedError() # pragma: nocover

async def write(self, buffer: bytes, timeout: float = None) -> None:
async def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
raise NotImplementedError() # pragma: nocover

async def aclose(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions httpcore/backends/mock.py
Expand Up @@ -22,7 +22,7 @@ def read(self, max_bytes: int, timeout: float = None) -> bytes:
return b""
return self._buffer.pop(0)

def write(self, buffer: bytes, timeout: float = None) -> None:
def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
pass

def close(self) -> None:
Expand Down Expand Up @@ -67,7 +67,7 @@ async def read(self, max_bytes: int, timeout: float = None) -> bytes:
return b""
return self._buffer.pop(0)

async def write(self, buffer: bytes, timeout: float = None) -> None:
async def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
pass

async def aclose(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion httpcore/backends/sync.py
Expand Up @@ -25,7 +25,7 @@ def read(self, max_bytes: int, timeout: float = None) -> bytes:
self._sock.settimeout(timeout)
return self._sock.recv(max_bytes)

def write(self, buffer: bytes, timeout: float = None) -> None:
def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
if not buffer:
return

Expand Down
2 changes: 1 addition & 1 deletion httpcore/backends/trio.py
Expand Up @@ -26,7 +26,7 @@ async def read(self, max_bytes: int, timeout: float = None) -> bytes:
with trio.fail_after(timeout_or_inf):
return await self._stream.receive_some(max_bytes=max_bytes)

async def write(self, buffer: bytes, timeout: float = None) -> None:
async def write(self, buffer: typing.Optional[bytes], timeout: float = None) -> None:
if not buffer:
return

Expand Down

0 comments on commit f9a9847

Please sign in to comment.