Skip to content

Commit

Permalink
Upgrade mypy to 0.930 (#6452)
Browse files Browse the repository at this point in the history
* Upgrade mypy to 0.930

* Update web_urldispatcher.py

* Update helpers.py

* More fixes.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Sam Bull <[email protected]>
Co-authored-by: Sam Bull <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 23, 2021
1 parent bb3aead commit eda8114
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def __init__(self, coro: Coroutine["asyncio.Future[Any]", None, _RetType]) -> No
def send(self, arg: None) -> "asyncio.Future[Any]":
return self._coro.send(arg)

def throw(self, arg: BaseException) -> None: # type: ignore[arg-type,override]
def throw(self, arg: BaseException) -> None: # type: ignore[override]
self._coro.throw(arg)

def close(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,11 @@ def links(self) -> "MultiDictProxy[MultiDictProxy[Union[str, URL]]]":

link.add(key, value)

key = link.get("rel", url) # type: ignore[assignment]
key = link.get("rel", url)

link.add("url", self.url.join(URL(url)))

links.add(key, MultiDictProxy(link))
links.add(str(key), MultiDictProxy(link))

return MultiDictProxy(links)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def get(self, key: str, default: Any = None) -> Any:

def __len__(self) -> int:
# reuses stored hash values if possible
return len(set().union(*self._maps)) # type: ignore[arg-type]
return len(set().union(*self._maps))

def __iter__(self) -> Iterator[str]:
d: Dict[str, Any] = {}
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def start_server(self, **kwargs: Any) -> None:
await site.start()
server = site._server
assert server is not None
sockets = server.sockets
sockets = server.sockets # type: ignore[attr-defined]
assert sockets is not None
self.port = sockets[0].getsockname()[1]
if self.scheme is sentinel:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async def _run_app(
) -> None:
# An internal function to actually do all dirty job for application running
if asyncio.iscoroutine(app):
app = await app # type: ignore[misc]
app = await app

app = cast(Application, app)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def addresses(self) -> List[Any]:
for site in self._sites:
server = site._server
if server is not None:
sockets = server.sockets
sockets = server.sockets # type: ignore[attr-defined]
if sockets is not None:
for sock in sockets:
ret.append(sock.getsockname())
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Iterator,
List,
Mapping,
NoReturn,
Optional,
Pattern,
Set,
Expand Down Expand Up @@ -928,18 +929,17 @@ class View(AbstractView):
async def _iter(self) -> StreamResponse:
if self.request.method not in hdrs.METH_ALL:
self._raise_allowed_methods()
method: Callable[[], Awaitable[StreamResponse]] = getattr(
method: Optional[Callable[[], Awaitable[StreamResponse]]] = getattr(
self, self.request.method.lower(), None
)
if method is None:
self._raise_allowed_methods()
resp = await method()
return resp
return await method()

def __await__(self) -> Generator[Any, None, StreamResponse]:
return self._iter().__await__()

def _raise_allowed_methods(self) -> None:
def _raise_allowed_methods(self) -> NoReturn:
allowed_methods = {m for m in hdrs.METH_ALL if hasattr(self, m.lower())}
raise HTTPMethodNotAllowed(self.request.method, allowed_methods)

Expand Down
6 changes: 3 additions & 3 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ multidict==5.2.0
# via
# -r requirements/multidict.txt
# yarl
mypy==0.910 ; implementation_name == "cpython"
mypy==0.930 ; implementation_name == "cpython"
# via
# -r requirements/lint.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -211,13 +211,13 @@ sphinxcontrib-towncrier==0.2.0a0
toml==0.10.2
# via
# cherry-picker
# mypy
# pre-commit
# pytest
# towncrier
tomli==1.2.2
# via
# coverage
# mypy
# pep517
towncrier==21.3.0
# via
Expand All @@ -229,7 +229,7 @@ trustme==0.9.0 ; platform_machine != "i686"
# via -r requirements/test.txt
typer==0.4.0
# via python-on-whales
typing-extensions==3.7.4.3
typing-extensions==3.10.0.0
# via
# -r requirements/typing-extensions.txt
# mypy
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r typing-extensions.txt
mypy==0.910; implementation_name=="cpython"
mypy==0.930; implementation_name=="cpython"
pre-commit==2.16.0
pytest==6.2.5
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.2
cryptography==36.0.1; platform_machine!="i686" # no 32-bit wheels; no python 3.9 wheels yet
freezegun==1.1.0
mypy==0.910; implementation_name=="cpython"
mypy==0.930; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
proxy.py ~= 2.4.0rc3
pytest==6.2.5
Expand Down
2 changes: 1 addition & 1 deletion requirements/typing-extensions.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
typing_extensions==3.7.4.3
typing_extensions==3.10
9 changes: 1 addition & 8 deletions tests/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def _find_all_importables(pkg: ModuleType) -> List[str]:
return sorted(
set(
chain.from_iterable(
_discover_path_importables(Path(p), pkg.__name__)
# FIXME: Unignore after upgrading to `mypy > 0.910`. The fix
# FIXME: is in the `master` branch of upstream since Aug 4,
# FIXME: 2021 but has not yet been included in any releases.
# Refs:
# * https://github.com/python/mypy/issues/1422
# * https://github.com/python/mypy/pull/9454
for p in pkg.__path__ # type: ignore[attr-defined]
_discover_path_importables(Path(p), pkg.__name__) for p in pkg.__path__
),
),
)
Expand Down

0 comments on commit eda8114

Please sign in to comment.