Skip to content

Commit

Permalink
chore(typing): "Fix" some more typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Oct 27, 2024
1 parent e773e38 commit e60f5f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
18 changes: 8 additions & 10 deletions ancv/visualization/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/web/test_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions tests/web/test_server.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e60f5f5

Please sign in to comment.