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 8, 2022
1 parent b159eac commit 95a0823
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * Run "pre-commit install".
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -16,7 +16,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.32.1
hooks:
- id: pyupgrade
args: [ "--py36-plus", "--keep-mock" ]
Expand All @@ -32,12 +32,12 @@ repos:
- id: isort

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v0.950
hooks:
- id: mypy
additional_dependencies: [ "pytest", "trio-typing", "packaging" ]
Expand Down
8 changes: 4 additions & 4 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_callable_name(func: Callable) -> str:

def _task_started(task: asyncio.Task) -> bool:
"""Return ``True`` if the task has been started and has not finished."""
coro = get_coro(task)
coro = cast(Coroutine[Any, Any, Any], get_coro(task))
try:
return getcoroutinestate(coro) in (CORO_RUNNING, CORO_SUSPENDED)
except AttributeError:
Expand Down Expand Up @@ -1362,7 +1362,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 @@ -1552,7 +1552,7 @@ async def create_udp_socket(
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 @@ -1568,7 +1568,7 @@ async def getaddrinfo(host: Union[bytes, str], port: Union[str, int, None], *,
proto: int = 0, flags: int = 0) -> GetAddrInfoReturnType:
# https://github.com/python/typeshed/pull/4304
result = await get_running_loop().getaddrinfo(
host, port, family=family, type=type, proto=proto, flags=flags) # type: ignore[arg-type]
host, port, family=family, type=type, proto=proto, flags=flags)
return cast(GetAddrInfoReturnType, result)


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 @@ -394,8 +394,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 @@ -102,7 +102,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 @@ -116,7 +118,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: asyncio.Task[None] = loop.create_task(coro) # type: ignore[arg-type]
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 @@ -546,7 +546,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 95a0823

Please sign in to comment.