Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mypy from 0.940 to 0.981 #6977

Merged
merged 18 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
uses: actions/checkout@v3.0.2
with:
submodules: true
- name: Setup Python 3.8
- name: Setup Python
uses: actions/setup-python@v4.3.0
with:
python-version: 3.8
python-version: 3.9
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
- name: Cache PyPI
uses: actions/cache@v3.0.11
with:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ async def _create_connection(
raise
raise UnixClientConnectorError(self.path, req.connection_key, exc) from exc

return cast(ResponseHandler, proto)
return proto


class NamedPipeConnector(BaseConnector):
Expand Down
26 changes: 10 additions & 16 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,29 +517,23 @@ async def _handle(self, request: Request) -> StreamResponse:

match_info.freeze()

resp = None
request._match_info = match_info
expect = request.headers.get(hdrs.EXPECT)
if expect:
resp = await match_info.expect_handler(request)
await match_info.expect_handler(request)
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
await request.writer.drain()

if resp is None:
handler = match_info.handler
handler = match_info.handler

if self._run_middlewares:
for app in match_info.apps[::-1]:
for m, new_style in app._middlewares_handlers: # type: ignore[union-attr] # noqa
if new_style:
handler = update_wrapper(
partial(m, handler=handler), handler
)
else:
handler = await m(app, handler) # type: ignore[arg-type]
if self._run_middlewares:
for app in match_info.apps[::-1]:
for m, new_style in app._middlewares_handlers: # type: ignore[union-attr] # noqa
if new_style:
handler = update_wrapper(partial(m, handler=handler), handler)
else:
handler = await m(app, handler) # type: ignore[arg-type]

resp = await handler(request)

return resp
return await handler(request)

def __call__(self) -> "Application":
"""gunicorn compatibility"""
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def start(self) -> None:
assert server is not None
self._server = await loop.create_unix_server(
server,
self._path, # type: ignore[arg-type]
self._path,
ssl=self._ssl_context,
backlog=self._backlog,
)
Expand Down
39 changes: 17 additions & 22 deletions examples/client_ws.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
#!/usr/bin/env python3
"""websocket cmd client for wssrv.py example."""
"""websocket cmd client for web_ws.py example."""

import argparse
import asyncio
import signal
import sys
from contextlib import suppress

import aiohttp


async def start_client(loop, url):
async def start_client(url: str) -> None:
name = input("Please enter your name: ")

# input reader
def stdin_callback():
line = sys.stdin.buffer.readline().decode("utf-8")
if not line:
loop.stop()
else:
ws.send_str(name + ": " + line)

loop.add_reader(sys.stdin.fileno(), stdin_callback)

async def dispatch():
async def dispatch(ws: aiohttp.ClientWebSocketResponse) -> None:
while True:
msg = await ws.receive()

Expand All @@ -30,7 +21,7 @@ async def dispatch():
elif msg.type == aiohttp.WSMsgType.BINARY:
print("Binary: ", msg.data)
elif msg.type == aiohttp.WSMsgType.PING:
ws.pong()
await ws.pong()
elif msg.type == aiohttp.WSMsgType.PONG:
print("Pong received")
else:
Expand All @@ -43,10 +34,18 @@ async def dispatch():

break

# send request
async with aiohttp.ClientSession() as session:
async with session.ws_connect(url, autoclose=False, autoping=False) as ws:
await dispatch()
# send request
dispatch_task = asyncio.create_task(dispatch(ws))

# Exit with Ctrl+D
while line := await asyncio.to_thread(sys.stdin.readline):
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
await ws.send_str(name + ": " + line)

dispatch_task.cancel()
with suppress(asyncio.CancelledError):
await dispatch_task


ARGS = argparse.ArgumentParser(
Expand All @@ -67,8 +66,4 @@ async def dispatch():

url = f"http://{args.host}:{args.port}"

loop = asyncio.get_event_loop()

loop.add_signal_handler(signal.SIGINT, loop.stop)
loop.create_task(start_client(loop, url))
loop.run_forever()
asyncio.run(start_client(url))
2 changes: 1 addition & 1 deletion examples/fake_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def resolve(self, host, port=0, family=socket.AF_INET):
return await self._resolver.resolve(host, port, family)

async def close(self) -> None:
self._resolver.close()
await self._resolver.close()


class FakeFacebook:
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ multidict==5.2.0
# via
# -r requirements/multidict.txt
# yarl
mypy==0.940 ; implementation_name == "cpython"
mypy==0.981 ; implementation_name == "cpython"
# via
# -r requirements/lint.txt
# -r requirements/test.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r typing-extensions.txt
aioredis==2.0.1
mypy==0.940; implementation_name=="cpython"
mypy==0.981; implementation_name=="cpython"
pre-commit==2.17.0
pytest==7.1.3
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Brotli==1.0.9
coverage==6.4.2
cryptography==36.0.1; platform_machine!="i686" # no 32-bit wheels; no python 3.9 wheels yet
freezegun==1.1.0
mypy==0.940; implementation_name=="cpython"
mypy==0.981; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
proxy.py ~= 2.4.4rc3
pytest==7.1.3
Expand Down