Skip to content

Commit

Permalink
Mypy coverage (#5457)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
Dreamsorcerer and Dreamsorcerer authored Feb 8, 2021
1 parent 1a98940 commit d6e51d9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
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
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

.develop: .install-deps $(call to-hash,$(PYS) $(CYS) $(CS))
pip install -e .
Expand Down
5 changes: 3 additions & 2 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 @@ -104,4 +104,5 @@ 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)
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

0 comments on commit d6e51d9

Please sign in to comment.