From c6518f6b39386a7c803d0c2792fdae6d61436064 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 15:07:38 +0100 Subject: [PATCH] Use builtin generics and `X | None` Since Python 3.9 and 3.10, `list`, `tuple`, and `X | None` replace `typing.List`, `typing.Tuple`, and `typing.Optional` --- noxfile.py | 3 ++- src/velofy/console/decorators.py | 3 ++- src/velofy/db/addresses_addresses.py | 7 +++---- src/velofy/db/forecasts.py | 3 +-- src/velofy/db/pixels.py | 3 +-- src/velofy/db/utils/locations.py | 10 ++++------ src/velofy/forecasts/methods/decomposition.py | 11 +++++------ src/velofy/forecasts/timify.py | 7 +++---- 8 files changed, 21 insertions(+), 26 deletions(-) diff --git a/noxfile.py b/noxfile.py index 68307b1..0cbe35e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,8 +27,9 @@ import itertools import os import pathlib import tempfile +from collections.abc import Generator from collections.abc import Mapping -from typing import Any, Generator +from typing import Any import nox from nox.sessions import Session diff --git a/src/velofy/console/decorators.py b/src/velofy/console/decorators.py index 513882a..19cbd6d 100644 --- a/src/velofy/console/decorators.py +++ b/src/velofy/console/decorators.py @@ -4,7 +4,8 @@ import functools import os import subprocess # noqa:S404 import sys -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import click diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index 83500a4..ee5415d 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -5,7 +5,6 @@ from __future__ import annotations import functools import itertools import json -from typing import List, Tuple import folium import googlemaps as gm @@ -127,7 +126,7 @@ class Path(meta.Base): cls, *addresses: db.Address, google_maps: bool = False, - ) -> List[Path]: + ) -> list[Path]: """Calculate pair-wise paths for `Address` objects. This is the main constructor method for the class. @@ -239,7 +238,7 @@ class Path(meta.Base): # get from A to B. As a step's "start_location" may equal the previous step's # "end_location", we use an `OrderedSet` to find the unique latitude-longitude # pairs that make up the path from `.first_address` to `.second_address`. - steps: ordered_set.OrderedSet[Tuple[float, float]] = ordered_set.OrderedSet() + steps: ordered_set.OrderedSet[tuple[float, float]] = ordered_set.OrderedSet() for step in route["steps"]: steps.add( (step["start_location"]["lat"], step["start_location"]["lng"]), @@ -262,7 +261,7 @@ class Path(meta.Base): return self.first_address.city.map @functools.cached_property - def waypoints(self) -> List[utils.Location]: + def waypoints(self) -> list[utils.Location]: """The couriers' route from `.first_address` to `.second_address`. The returned `Location`s all relate to `.first_address.city.southwest`. diff --git a/src/velofy/db/forecasts.py b/src/velofy/db/forecasts.py index 2ab4c14..45717e8 100644 --- a/src/velofy/db/forecasts.py +++ b/src/velofy/db/forecasts.py @@ -4,7 +4,6 @@ from __future__ import annotations import datetime as dt import math -from typing import List import pandas as pd import sqlalchemy as sa @@ -193,7 +192,7 @@ class Forecast(meta.Base): train_horizon: int, model: str, data: pd.Dataframe, - ) -> List[db.Forecast]: + ) -> list[db.Forecast]: """Convert results from the forecasting `*Model`s into `Forecast` objects. This is an alternative constructor method. diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index 96cf050..61d155a 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -3,7 +3,6 @@ from __future__ import annotations import functools -from typing import List import folium import sqlalchemy as sa @@ -131,7 +130,7 @@ class Pixel(meta.Base): return location @functools.cached_property - def restaurants(self) -> List[db.Restaurant]: # pragma: no cover + def restaurants(self) -> list[db.Restaurant]: # pragma: no cover """Obtain all `Restaurant`s in `self`.""" return ( db.session.query(db.Restaurant) diff --git a/src/velofy/db/utils/locations.py b/src/velofy/db/utils/locations.py index 21b4eef..df7ef6b 100644 --- a/src/velofy/db/utils/locations.py +++ b/src/velofy/db/utils/locations.py @@ -2,8 +2,6 @@ from __future__ import annotations -from typing import Optional, Tuple - import utm @@ -38,8 +36,8 @@ class Location: self._zone = zone self._band = band.upper() - self._normalized_easting: Optional[int] = None - self._normalized_northing: Optional[int] = None + self._normalized_easting: int | None = None + self._normalized_northing: int | None = None def __repr__(self) -> str: """A non-literal text representation in the UTM system. @@ -72,7 +70,7 @@ class Location: return self._longitude @property - def lat_lng(self) -> Tuple[float, float]: + def lat_lng(self) -> tuple[float, float]: """The `.latitude` and `.longitude` as a 2-`tuple`.""" return self._latitude, self._longitude @@ -92,7 +90,7 @@ class Location: return f"{self._zone}{self._band}" @property - def zone_details(self) -> Tuple[int, str]: + def zone_details(self) -> tuple[int, str]: """The UTM zone of the location as the zone number and the band.""" return self._zone, self._band diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index 5d5d827..b77934f 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -5,7 +5,6 @@ using the `rpy2` library. """ import math -from typing import Optional import pandas as pd from rpy2 import robjects @@ -17,14 +16,14 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 *, frequency: int, ns: int, - nt: Optional[int] = None, - nl: Optional[int] = None, + nt: int | None = None, + nl: int | None = None, ds: int = 0, dt: int = 1, dl: int = 1, - js: Optional[int] = None, - jt: Optional[int] = None, - jl: Optional[int] = None, + js: int | None = None, + jt: int | None = None, + jl: int | None = None, ni: int = 2, no: int = 0, ) -> pd.DataFrame: diff --git a/src/velofy/forecasts/timify.py b/src/velofy/forecasts/timify.py index 826afc6..457e0a5 100644 --- a/src/velofy/forecasts/timify.py +++ b/src/velofy/forecasts/timify.py @@ -3,7 +3,6 @@ from __future__ import annotations import datetime as dt -from typing import Tuple import pandas as pd import sqlalchemy as sa @@ -244,7 +243,7 @@ class OrderHistory: pixel_id: int, predict_at: dt.datetime, train_horizon: int, - ) -> Tuple[pd.Series, int, pd.Series]: + ) -> tuple[pd.Series, int, pd.Series]: """Slice a horizontal time series out of the `.totals`. Create a time series covering `train_horizon` weeks that can be used @@ -316,7 +315,7 @@ class OrderHistory: pixel_id: int, predict_day: dt.date, train_horizon: int, - ) -> Tuple[pd.Series, int, pd.Series]: + ) -> tuple[pd.Series, int, pd.Series]: """Slice a vertical time series out of the `.totals`. Create a time series covering `train_horizon` weeks that can be used @@ -405,7 +404,7 @@ class OrderHistory: pixel_id: int, predict_at: dt.datetime, train_horizon: int, - ) -> Tuple[pd.Series, int, pd.Series]: + ) -> tuple[pd.Series, int, pd.Series]: """Slice a vertical real-time time series out of the `.totals`. Create a time series covering `train_horizon` weeks that can be used