Skip to content

Commit

Permalink
Updated pre-commit modules and fixed resulting mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed May 5, 2022
1 parent 987b500 commit c4aeb6b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ repos:
- id: isort

- repo: https://github.com/csachs/pyproject-flake8
rev: v0.0.1a3
rev: v0.0.1a4
hooks:
- id: pyproject-flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
rev: v0.950
hooks:
- id: mypy
additional_dependencies: [ "pytest", "trio-typing", "packaging" ]
Expand Down
8 changes: 3 additions & 5 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ async def accept(self) -> abc.SocketStream:

client_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
transport, protocol = await self._loop.connect_accepted_socket(StreamProtocol, client_sock)
return SocketStream(cast(asyncio.Transport, transport), cast(StreamProtocol, protocol))
return SocketStream(cast(asyncio.Transport, transport), protocol)

async def aclose(self) -> None:
if self._closed:
Expand Down Expand Up @@ -1785,7 +1785,7 @@ async def create_udp_socket(cls, family: AddressFamily, local_address: IPSockAdd
DatagramProtocol, local_addr=local_address, remote_addr=remote_address, family=family,
reuse_port=reuse_port)
transport = cast(asyncio.DatagramTransport, result[0])
protocol = cast(DatagramProtocol, result[1])
protocol = result[1]
if protocol.exception:
transport.close()
raise protocol.exception
Expand All @@ -1799,10 +1799,8 @@ async def create_udp_socket(cls, family: AddressFamily, local_address: IPSockAdd
async def getaddrinfo(cls, host: str | bytes, port: str | int | None, *,
family: int | AddressFamily = 0, type: int | SocketKind = 0,
proto: int = 0, flags: int = 0) -> GetAddrInfoReturnType:
# https://github.com/python/typeshed/pull/7517
result = await get_running_loop().getaddrinfo(
host, port, family=family, type=type, proto=proto, # type: ignore[arg-type]
flags=flags)
host, port, family=family, type=type, proto=proto, flags=flags)
return cast(GetAddrInfoReturnType, result)

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions src/anyio/from_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ async def run_portal() -> None:

future: Future[BlockingPortal] = Future()
with ThreadPoolExecutor(1) as executor:
run_future = executor.submit(_eventloop.run, run_portal, backend=backend,
backend_options=backend_options)
run_future = executor.submit(
_eventloop.run,
run_portal, # type: ignore[arg-type]
backend=backend,
backend_options=backend_options
)
try:
wait(cast(Iterable[Future], [run_future, future]), return_when=FIRST_COMPLETED)
except BaseException:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def generator_part() -> Generator[object, BaseException, None]:
yield from event.wait()

event = asyncio.Event()
gen_task = asyncio_event_loop.create_task(generator_part())
gen_task: asyncio.Task[None] = asyncio_event_loop.create_task(
generator_part() # type: ignore[arg-type]
)
asyncio_event_loop.run_until_complete(native_coro_part())


Expand All @@ -115,7 +117,7 @@ async def agen_func() -> AsyncGenerator[None, None]:
agen = agen_func()
coro = agen.asend(None)
loop = asyncio.get_event_loop()
task = loop.create_task(coro)
task = loop.create_task(cast(Coroutine[Any, Any, Any], coro))
await wait_all_tasks_blocked()
await task
await agen.aclose()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ async def host_agen_fn() -> AsyncGenerator[None, None]:

host_agen = host_agen_fn()
try:
await asyncio.get_event_loop().create_task(host_agen.__anext__())
await asyncio.get_event_loop().create_task(host_agen.__anext__()) # type: ignore[arg-type]
finally:
await host_agen.aclose()

Expand Down

0 comments on commit c4aeb6b

Please sign in to comment.