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`
This commit is contained in:
Alexander Hess 2026-11-30 15:07:38 +01:00
commit c6518f6b39
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
8 changed files with 21 additions and 26 deletions

View file

@ -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

View file

@ -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

View file

@ -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`.

View file

@ -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.

View file

@ -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)

View file

@ -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

View file

@ -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:

View file

@ -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