diff --git a/noxfile.py b/noxfile.py index 0cbe35e..1fc09ca 100644 --- a/noxfile.py +++ b/noxfile.py @@ -23,20 +23,19 @@ e.g., `uv run nox -s test -- tests/test_config.py`. """ import collections +import collections.abc as cabc import itertools import os import pathlib import tempfile -from collections.abc import Generator -from collections.abc import Mapping -from typing import Any +import typing as t import nox from nox.sessions import Session from packaging import version as pkg_version -def nested_defaultdict() -> collections.defaultdict[str, Any]: +def nested_defaultdict() -> collections.defaultdict[str, t.Any]: """Create a multi-level `defaultdict` with variable depth. The returned `dict`ionary never raises a `KeyError` @@ -48,9 +47,9 @@ def nested_defaultdict() -> collections.defaultdict[str, Any]: return collections.defaultdict(nested_defaultdict) -def defaultify(obj: Any) -> Any: +def defaultify(obj: t.Any) -> t.Any: """Turn nested `dict`s into nested `defaultdict`s.""" - if isinstance(obj, Mapping): + if isinstance(obj, cabc.Mapping): return collections.defaultdict( nested_defaultdict, {key: defaultify(val) for key, val in obj.items()}, @@ -58,7 +57,7 @@ def defaultify(obj: Any) -> Any: return obj -def load_pyproject_toml() -> collections.defaultdict[str, Any]: +def load_pyproject_toml() -> collections.defaultdict[str, t.Any]: """Load the contents of the pyproject.toml file. The contents are represented as a `nested_defaultdict`; @@ -522,7 +521,7 @@ def clean_cwd(session: Session) -> None: session.run("rm", "-rf", path) -def _expand(*patterns: str) -> Generator[pathlib.Path, None, None]: +def _expand(*patterns: str) -> cabc.Generator[pathlib.Path, None, None]: """Expand glob patterns into (resolved) paths. Args: @@ -600,7 +599,7 @@ def start(session: Session) -> None: def install_pinned( session: Session, *packages_or_pip_args: str, - **kwargs: Any, + **kwargs: t.Any, ) -> None: """Install packages respecting the uv.lock file. diff --git a/src/velofy/console/decorators.py b/src/velofy/console/decorators.py index 19cbd6d..4c9a5d9 100644 --- a/src/velofy/console/decorators.py +++ b/src/velofy/console/decorators.py @@ -1,25 +1,24 @@ """Utils for the CLI scripts.""" +import collections.abc as cabc import functools import os import subprocess # noqa:S404 import sys -from collections.abc import Callable -from typing import Any +import typing as t import click -def db_revision( - rev: str, -) -> Callable[..., Callable[..., Any]]: # pragma: no cover -> easy to check visually +def db_revision(rev: str) -> cabc.Callable[..., cabc.Callable[..., t.Any]]: """A decorator ensuring the database is at a given revision.""" - def decorator(func: Callable[..., Any]) -> Callable[..., Any]: + def decorator(func: cabc.Callable[..., t.Any]) -> cabc.Callable[..., t.Any]: @functools.wraps(func) - def ensure(*args: Any, **kwargs: Any) -> Any: + def ensure(*args: t.Any, **kwargs: t.Any) -> t.Any: """Do not execute the `func` if the revision does not match.""" - if not os.getenv("TESTING"): + # Skip in tests as the database then either has no or the latest revision + if not os.getenv("TESTING"): # pragma: no cover result = subprocess.run( # noqa:S603,S607 ["alembic", "current"], # noqa:S607 capture_output=True, diff --git a/src/velofy/console/main.py b/src/velofy/console/main.py index 0874530..8446905 100644 --- a/src/velofy/console/main.py +++ b/src/velofy/console/main.py @@ -1,6 +1,6 @@ """The entry point for all CLI scripts in the project.""" -from typing import Any +import typing as t import click from click import core as cli_core @@ -8,7 +8,7 @@ from click import core as cli_core import velofy -def show_version(ctx: cli_core.Context, _param: Any, value: bool) -> None: +def show_version(ctx: cli_core.Context, _param: t.Any, value: bool) -> None: """Show the package's version.""" # If --version / -V is NOT passed in, # continue with the command. diff --git a/src/velofy/db/addresses.py b/src/velofy/db/addresses.py index 00238a6..34564a1 100644 --- a/src/velofy/db/addresses.py +++ b/src/velofy/db/addresses.py @@ -4,7 +4,7 @@ from __future__ import annotations import datetime as dt import functools -from typing import Any +import typing as t import folium import sqlalchemy as sa @@ -185,7 +185,7 @@ class Address(meta.Base): """Shortcut to the `.city.map` object.""" return self.city.map - def draw(self, **kwargs: Any) -> folium.Map: # pragma: no cover + def draw(self, **kwargs: t.Any) -> folium.Map: # pragma: no cover """Draw the address on the `.city.map`. By default, addresses are shown as black dots. @@ -197,7 +197,7 @@ class Address(meta.Base): Returns: `.city.map` for convenience in interactive usage """ - defaults: dict[str, Any] = { + defaults: dict[str, t.Any] = { "color": f"{config.NEUTRAL_COLOR}", "popup": f"{self.street}, {self.zip_code} {self.city_name}", } diff --git a/src/velofy/db/connection.py b/src/velofy/db/connection.py index 3ca9d5c..1e29d81 100644 --- a/src/velofy/db/connection.py +++ b/src/velofy/db/connection.py @@ -8,7 +8,7 @@ That is the case on the CI server. """ import os -from typing import cast +import typing as t import sqlalchemy as sa from sqlalchemy import orm @@ -21,5 +21,5 @@ if os.getenv("TESTING"): session: orm.Session = None # type: ignore[assignment] else: # pragma: no cover - engine = sa.create_engine(cast(str, velofy.config.DATABASE_URI)) + engine = sa.create_engine(t.cast(str, velofy.config.DATABASE_URI)) session = orm.Session(bind=engine) diff --git a/src/velofy/db/grids.py b/src/velofy/db/grids.py index 9821ade..ec8802e 100644 --- a/src/velofy/db/grids.py +++ b/src/velofy/db/grids.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Any +import typing as t import folium import sqlalchemy as sa @@ -136,7 +136,7 @@ class Grid(meta.Base): """Shortcut to the `.city.map` object.""" return self.city.map - def draw(self, **kwargs: Any) -> folium.Map: # pragma: no cover + def draw(self, **kwargs: t.Any) -> folium.Map: # pragma: no cover """Draw all pixels in the grid. Args: diff --git a/src/velofy/db/meta.py b/src/velofy/db/meta.py index ff86eb2..3901514 100644 --- a/src/velofy/db/meta.py +++ b/src/velofy/db/meta.py @@ -1,6 +1,6 @@ """Provide the ORM's declarative base.""" -from typing import Any +import typing as t import sqlalchemy as sa from sqlalchemy import orm @@ -8,7 +8,7 @@ from sqlalchemy import orm import velofy -Base: Any = orm.declarative_base( +Base: t.Any = orm.declarative_base( metadata=sa.MetaData( schema=velofy.config.CLEAN_SCHEMA, naming_convention={