From e60f5f55b3356428c3e59a916f9825a80ace0c64 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Sun, 27 Oct 2024 14:13:44 +0100 Subject: [PATCH] chore(typing): "Fix" some more typing issues --- ancv/visualization/templates.py | 18 ++++++++---------- tests/web/test_client.py | 4 ++-- tests/web/test_server.py | 5 +++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ancv/visualization/templates.py b/ancv/visualization/templates.py index d0ba3a7..73b9207 100644 --- a/ancv/visualization/templates.py +++ b/ancv/visualization/templates.py @@ -857,19 +857,11 @@ def __rich_console__( yield NewLine() - # Need to help `mypy` type inference out a bit here. - items: Optional[Iterable[ResumeItem]] - title: str - # Shortcut names m = self.model t = self.translation - # The 'main loop'. All items are rendered through `singledispatch`. This is - # somewhat elegant, but has limitations: all elements can only easily be - # rendered on their own, forcing sequential flow. Multi-column outputs are not - # possible, for example. - for items, title in [ + items_with_title: list[tuple[Optional[Iterable[ResumeItem]], str]] = [ (m.work, t.work), (m.education, t.education), (m.skills, t.skills), @@ -881,7 +873,13 @@ def __rich_console__( (m.volunteer, t.volunteer), (m.projects, t.projects), (m.interests, t.interests), - ]: + ] + + # The 'main loop'. All items are rendered through `singledispatch`. This is + # somewhat elegant, but has limitations: all elements can only easily be + # rendered on their own, forcing sequential flow. Multi-column outputs are not + # possible, for example. + for items, title in items_with_title: # Key aka section might be missing entirely (`None`) *or* be empty (`[]`), # the latter of which type checking cannot protect against. In either case, # skip the section. diff --git a/tests/web/test_client.py b/tests/web/test_client.py index 1f65ad1..7727db8 100644 --- a/tests/web/test_client.py +++ b/tests/web/test_client.py @@ -1,6 +1,6 @@ import asyncio +from contextlib import AbstractContextManager from contextlib import nullcontext as does_not_raise -from typing import ContextManager import aiohttp import pytest @@ -81,7 +81,7 @@ async def test_get_resume_validations( username: str, size_limit: int, filename: str, - expectation: ContextManager, + expectation: AbstractContextManager[pytest.ExceptionInfo[BaseException]], # Unsure # Fixtures: gh_api: GitHubAPI, stopwatch: Stopwatch, diff --git a/tests/web/test_server.py b/tests/web/test_server.py index 89b2346..d032115 100644 --- a/tests/web/test_server.py +++ b/tests/web/test_server.py @@ -1,8 +1,9 @@ import asyncio +from contextlib import AbstractContextManager from contextlib import nullcontext as does_not_raise from datetime import timedelta from http import HTTPStatus -from typing import Any, ContextManager, Optional +from typing import Any, Optional import pytest from aiohttp.client import ClientResponse @@ -290,7 +291,7 @@ async def test_root_endpoint( def test_server_timing_header( timings: dict[str, timedelta], expected: str, - expectation: ContextManager, + expectation: AbstractContextManager[pytest.ExceptionInfo[BaseException]], # Unsure ) -> None: with expectation: assert server_timing_header(timings) == expected