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

Mypy coverage #5457

Merged
merged 5 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
35 changes: 28 additions & 7 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
[mypy]
warn_unused_configs = True
strict = True
files = aiohttp, examples, tests
check_untyped_defs = True
follow_imports_for_stubs = True
#disallow_any_decorated = True
Copy link
Member Author

@Dreamsorcerer Dreamsorcerer Feb 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 commented out, we should consider in the future, but will need a ~50 errors to be cleaned up or ignored first.

disallow_any_generics = True
disallow_incomplete_defs = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
implicit_reexport = False
no_implicit_optional = True
show_error_codes = True
strict_equality = True
warn_incomplete_stub = True
warn_redundant_casts = True
#warn_unreachable = True
warn_unused_ignores = True
disallow_any_unimported = True
warn_return_any = True

[mypy-tests.*]
disallow_untyped_defs = False

[mypy-aiodns]
ignore_missing_imports = True

[mypy-brotli]
[mypy-asynctest]
ignore_missing_imports = True

[mypy-gunicorn.*]
[mypy-brotli]
ignore_missing_imports = True

[mypy-uvloop]
[mypy-cchardet]
ignore_missing_imports = True

[mypy-cchardet]
[mypy-gunicorn.*]
ignore_missing_imports = True

[mypy-tokio]
ignore_missing_imports = True

[mypy-asynctest]
[mypy-uvloop]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions CHANGES/5457.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve Mypy coverage.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fmt format:

.PHONY: mypy
mypy:
mypy --show-error-codes aiohttp tests
mypy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With no arguments, it uses the files and options in the config file.


.develop: .install-deps $(call to-hash,$(PYS) $(CYS) $(CS))
pip install -e .
Expand Down
6 changes: 3 additions & 3 deletions aiohttp/resolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import socket
from typing import Any, Dict, List
from typing import Any, Dict, List, Type, Union

from .abc import AbstractResolver

Expand Down Expand Up @@ -103,5 +103,5 @@ async def resolve(
async def close(self) -> None:
self._resolver.cancel()


DefaultResolver = AsyncResolver if aiodns_default else ThreadedResolver
_DefaultType = Type[Union[AsyncResolver, ThreadedResolver]]
DefaultResolver: _DefaultType = AsyncResolver if aiodns_default else ThreadedResolver
2 changes: 1 addition & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
__all__ = ("GunicornWebWorker", "GunicornUVLoopWebWorker", "GunicornTokioWebWorker")


class GunicornWebWorker(base.Worker): # type: ignore[misc]
class GunicornWebWorker(base.Worker): # type: ignore[misc,no-any-unimported]

DEFAULT_AIOHTTP_LOG_FORMAT = AccessLogger.LOG_FORMAT
DEFAULT_GUNICORN_LOG_FORMAT = GunicornAccessLogFormat.default
Expand Down
2 changes: 1 addition & 1 deletion examples/background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def listen_to_redis(app: web.Application) -> None:


async def start_background_tasks(app: web.Application) -> None:
app["redis_listener"] = app.loop.create_task(listen_to_redis(app))
app["redis_listener"] = asyncio.create_task(listen_to_redis(app))


async def cleanup_background_tasks(app: web.Application) -> None:
Expand Down
2 changes: 1 addition & 1 deletion examples/client_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import aiohttp


async def fetch(session: aiohttp.ClientSession):
async def fetch(session: aiohttp.ClientSession) -> None:
print("Query http://httpbin.org/get")
async with session.get("http://httpbin.org/get") as resp:
print(resp.status)
Expand Down
5 changes: 3 additions & 2 deletions examples/fake_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from typing import Any, Dict, List, Union

from aiohttp import ClientSession, TCPConnector, resolver, test_utils, web
from aiohttp.abc import AbstractResolver


class FakeResolver:
class FakeResolver(AbstractResolver):
_LOCAL_HOST = {0: "127.0.0.1", socket.AF_INET: "127.0.0.1", socket.AF_INET6: "::1"}

def __init__(self, fakes: Dict[str, int]) -> None:
Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self) -> None:
web.get("/v2.7/me/friends", self.on_my_friends),
]
)
self.runner = None
self.runner = web.AppRunner(self.app)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example has clearly not been run in several years. :P

here = pathlib.Path(__file__)
ssl_cert = here.parent / "server.crt"
ssl_key = here.parent / "server.key"
Expand Down
5 changes: 3 additions & 2 deletions examples/web_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from pprint import pformat
from typing import NoReturn

from aiohttp import web

Expand All @@ -22,13 +23,13 @@ async def root(request: web.Request) -> web.StreamResponse:
return resp


async def login(request: web.Request) -> None:
async def login(request: web.Request) -> NoReturn:
exc = web.HTTPFound(location="/")
exc.set_cookie("AUTH", "secret")
raise exc


async def logout(request: web.Request) -> None:
async def logout(request: web.Request) -> NoReturn:
exc = web.HTTPFound(location="/")
exc.del_cookie("AUTH")
raise exc
Expand Down