Skip to content

Commit

Permalink
style: Enforce mypy no-implicit-optional setting
Browse files Browse the repository at this point in the history
Which has been introduced in `mypy==0.981` and enforce proper type
annotations for args / kwargs with default `None` value.
  • Loading branch information
playpauseandstop committed Oct 23, 2022
1 parent b1ef521 commit af644db
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.badabump]
version_type = "semver"
version_files = ["./pyproject.toml", "./src/aiohttp_middlewares/__init__.py"]
version_files = [
"./pyproject.toml",
"./src/aiohttp_middlewares/__init__.py",
]

[tool.black]
line_length = 79
Expand All @@ -14,6 +21,8 @@ source = ["aiohttp_middlewares"]
source = ["./src/"]

[tool.coverage.report]
exclude_lines = ["if TYPE_CHECKING:", "@overload"]
omit = ["./src/*/__main__.py", "./src/*/annotations.py"]
fail_under = 95
skip_covered = true
show_missing = true
Expand All @@ -40,6 +49,7 @@ follow_imports = "normal"
follow_imports_for_stubs = true
ignore_missing_imports = false
namespace_packages = true
no_implicit_optional = true
mypy_path = "./src/"
python_executable = "./.venv/bin/python3"
show_column_numbers = true
Expand Down Expand Up @@ -149,7 +159,3 @@ commands_pre =
poetry install --only main,test
poetry run python3 -m pip install aiohttp==3.8.1 async-timeout==4.0.2 yarl==1.5.1
"""

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
10 changes: 5 additions & 5 deletions src/aiohttp_middlewares/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

import logging
import re
from typing import Pattern, Tuple
from typing import Pattern, Tuple, Union

from aiohttp import web

Expand Down Expand Up @@ -158,13 +158,13 @@
def cors_middleware(
*,
allow_all: bool = False,
origins: UrlCollection = None,
urls: UrlCollection = None,
expose_headers: StrCollection = None,
origins: Union[UrlCollection, None] = None,
urls: Union[UrlCollection, None] = None,
expose_headers: Union[StrCollection, None] = None,
allow_headers: StrCollection = DEFAULT_ALLOW_HEADERS,
allow_methods: StrCollection = DEFAULT_ALLOW_METHODS,
allow_credentials: bool = False,
max_age: int = None,
max_age: Union[int, None] = None,
) -> Middleware:
"""Middleware to provide CORS headers for aiohttp applications.
Expand Down
12 changes: 8 additions & 4 deletions src/aiohttp_middlewares/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def error_context(request: web.Request) -> Iterator[ErrorContext]:
def error_middleware(
*,
default_handler: Handler = default_error_handler,
config: Config = None,
ignore_exceptions: Union[ExceptionType, Tuple[ExceptionType, ...]] = None,
config: Union[Config, None] = None,
ignore_exceptions: Union[
ExceptionType, Tuple[ExceptionType, ...], None
] = None,
) -> Middleware:
"""Middleware to handle exceptions in aiohttp applications.
Expand Down Expand Up @@ -240,8 +242,10 @@ async def get_error_response(
err: Exception,
*,
default_handler: Handler = default_error_handler,
config: Config = None,
ignore_exceptions: Union[ExceptionType, Tuple[ExceptionType, ...]] = None,
config: Union[Config, None] = None,
ignore_exceptions: Union[
ExceptionType, Tuple[ExceptionType, ...], None
] = None,
) -> web.StreamResponse:
"""Actual coroutine to get response for given request & error.
Expand Down
5 changes: 4 additions & 1 deletion src/aiohttp_middlewares/https.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

import logging
from typing import Union

from aiohttp import web

Expand All @@ -36,7 +37,9 @@
logger = logging.getLogger(__name__)


def https_middleware(match_headers: DictStrStr = None) -> Middleware:
def https_middleware(
match_headers: Union[DictStrStr, None] = None
) -> Middleware:
"""
Change scheme for current request when aiohttp application deployed behind
reverse proxy with HTTPS enabled.
Expand Down
6 changes: 5 additions & 1 deletion src/aiohttp_middlewares/shield.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import asyncio
import logging
from typing import Union

from aiohttp import web

Expand All @@ -69,7 +70,10 @@


def shield_middleware(
*, methods: StrCollection = None, urls: Urls = None, ignore: Urls = None
*,
methods: Union[StrCollection, None] = None,
urls: Union[Urls, None] = None,
ignore: Union[Urls, None] = None,
) -> Middleware:
"""
Ensure that handler execution would not break on
Expand Down
2 changes: 1 addition & 1 deletion src/aiohttp_middlewares/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@


def timeout_middleware(
seconds: Union[int, float], *, ignore: Urls = None
seconds: Union[int, float], *, ignore: Union[Urls, None] = None
) -> Middleware:
"""Ensure that request handling does not exceed X seconds.
Expand Down

0 comments on commit af644db

Please sign in to comment.