Import typing as t ...
... and `collections.abc` as `cabc` Linting rule for `velofy`: Import modules instead of objects
This commit is contained in:
parent
c6518f6b39
commit
9c3b52befb
6 changed files with 26 additions and 28 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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}",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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={
|
||||
|
|
|
|||
Loading…
Reference in a new issue