Skip to content

Commit

Permalink
chore(typing): Polish various lints & typing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Oct 27, 2024
1 parent cb5b24e commit e773e38
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 26 deletions.
8 changes: 5 additions & 3 deletions ancv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from enum import IntEnum
from pathlib import Path

from ancv.typehelp import unwrap

PROJECT_ROOT = Path(__file__).parent
PACKAGE = __package__
PACKAGE = unwrap(__package__)


class SIPrefix(IntEnum):
KILO = 1e3
MEGA = 1e6
KILO = int(1e3)
MEGA = int(1e6)
3 changes: 2 additions & 1 deletion ancv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ def generate_schema() -> None:
"""

import json
import typing as t

from ancv.reflection import METADATA
from ancv.visualization.templates import Template
from ancv.visualization.themes import THEMES
from ancv.visualization.translations import TRANSLATIONS

schema = {
schema: dict[str, t.Any] = {
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [
{
Expand Down
12 changes: 12 additions & 0 deletions ancv/typehelp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import typing as t

T = t.TypeVar("T")


def unwrap(value: None | T) -> T:
"""Like Rust."""

if value is None:
raise ValueError("Provided value is `None`")

return value
8 changes: 4 additions & 4 deletions ancv/web/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

LOGGER = get_logger()

_SHOWCASE_RESUME = Template.from_file(
SHOWCASE_RESUME = Template.from_file(
PROJECT_ROOT / "data" / "showcase.resume.json"
).render()

_SHOWCASE_USERNAME = "heyho"
SHOWCASE_USERNAME = "heyho"


def is_terminal_client(user_agent: str) -> bool:
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(
[
# Order matters, see also https://www.grandmetric.com/2020/07/08/routing-order-in-aiohttp-library-in-python/
web.get("/", self.root),
web.get(f"/{_SHOWCASE_USERNAME}", self.showcase),
web.get(f"/{SHOWCASE_USERNAME}", self.showcase),
web.get("/{username}", self.username),
]
)
Expand Down Expand Up @@ -166,7 +166,7 @@ async def root(self, request: web.Request) -> web.Response:
async def showcase(self, request: web.Request) -> web.Response:
"""The showcase endpoint, returning a static resume."""

return web.Response(text=_SHOWCASE_RESUME)
return web.Response(text=SHOWCASE_RESUME)

async def username(self, request: web.Request) -> web.Response:
"""The username endpoint, returning a dynamic resume from a user's gists."""
Expand Down
2 changes: 1 addition & 1 deletion devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"python@3.12",
"uv@0.4",
"ruff@0.4",
"ruff@0.7",
"pydeps@1.12",
"graphviz@8",
"pre-commit@3"
Expand Down
24 changes: 12 additions & 12 deletions devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,51 +234,51 @@
}
}
},
"ruff@0.4": {
"last_modified": "2024-06-21T15:31:59Z",
"resolved": "github:NixOS/nixpkgs/90338afd6177fc683a04d934199d693708c85a3b#ruff",
"ruff@0.7": {
"last_modified": "2024-10-18T06:41:56Z",
"resolved": "github:NixOS/nixpkgs/c858402c2a629211153137fb8d39be9fde4694ff#ruff",
"source": "devbox-search",
"version": "0.4.10",
"version": "0.7.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/imr1jyig7di4a8lcd8ypvqkag46fnafq-ruff-0.4.10",
"path": "/nix/store/p80xrz0y1qs4z27bbpwp6jlxd8a137v3-ruff-0.7.0",
"default": true
}
],
"store_path": "/nix/store/imr1jyig7di4a8lcd8ypvqkag46fnafq-ruff-0.4.10"
"store_path": "/nix/store/p80xrz0y1qs4z27bbpwp6jlxd8a137v3-ruff-0.7.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/wr81if4p582l5jv0nrygb954f14lqf7j-ruff-0.4.10",
"path": "/nix/store/i32qgcbfr07l10dpkhhs9482yg7chb2v-ruff-0.7.0",
"default": true
}
],
"store_path": "/nix/store/wr81if4p582l5jv0nrygb954f14lqf7j-ruff-0.4.10"
"store_path": "/nix/store/i32qgcbfr07l10dpkhhs9482yg7chb2v-ruff-0.7.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/qjlq4gpvfzfnc2p9ki4ha9aq75dwxika-ruff-0.4.10",
"path": "/nix/store/il9zkd76yw8xdq1ia09napdkqardh7gk-ruff-0.7.0",
"default": true
}
],
"store_path": "/nix/store/qjlq4gpvfzfnc2p9ki4ha9aq75dwxika-ruff-0.4.10"
"store_path": "/nix/store/il9zkd76yw8xdq1ia09napdkqardh7gk-ruff-0.7.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/wylssm8c60cyiab1a48wm0jlxq51qa73-ruff-0.4.10",
"path": "/nix/store/6ix6r6c9xbh442ax04pm72kzrp6cyvga-ruff-0.7.0",
"default": true
}
],
"store_path": "/nix/store/wylssm8c60cyiab1a48wm0jlxq51qa73-ruff-0.4.10"
"store_path": "/nix/store/6ix6r6c9xbh442ax04pm72kzrp6cyvga-ruff-0.7.0"
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions tests/web/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from aiohttp.web import Application

from ancv.web.server import (
_SHOWCASE_RESUME,
_SHOWCASE_USERNAME,
SHOWCASE_RESUME,
SHOWCASE_USERNAME,
is_terminal_client,
server_timing_header,
)
Expand Down Expand Up @@ -160,9 +160,9 @@ async def test_showcase_endpoint(

client = await aiohttp_client(api_client_app)

resp: ClientResponse = await client.get(f"/{_SHOWCASE_USERNAME}")
resp: ClientResponse = await client.get(f"/{SHOWCASE_USERNAME}")
assert resp.status == HTTPStatus.OK
assert await resp.text() == _SHOWCASE_RESUME
assert await resp.text() == SHOWCASE_RESUME

@pytest.mark.parametrize(
["username", "expected_contained_text"],
Expand Down Expand Up @@ -297,4 +297,4 @@ def test_server_timing_header(


def test_exact_showcase_output(showcase_output: str) -> None:
assert _SHOWCASE_RESUME == showcase_output
assert SHOWCASE_RESUME == showcase_output

0 comments on commit e773e38

Please sign in to comment.