diff --git a/src/velofy/db/addresses.py b/src/velofy/db/addresses.py index 42c43aa..2ba8588 100644 --- a/src/velofy/db/addresses.py +++ b/src/velofy/db/addresses.py @@ -179,7 +179,7 @@ class Address(meta.Base): """ return self.location.y - def clear_map(self) -> "Address": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Shortcut to the `.city.clear_map()` method. Returns: diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index 16a50aa..af14092 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -3,6 +3,7 @@ import functools import itertools import json +import typing as t import folium import googlemaps as gm @@ -124,7 +125,7 @@ class Path(meta.Base): cls, *addresses: db.Address, google_maps: bool = False, - ) -> list["Path"]: + ) -> list[t.Self]: """Calculate pair-wise paths for `Address` objects. This is the main constructor method for the class. @@ -151,9 +152,9 @@ class Path(meta.Base): # If there is no `Path` object in the database ... path = ( - db.session.query(db.Path) - .filter(db.Path.first_address == first) - .filter(db.Path.second_address == second) + db.session.query(cls) + .filter(cls.first_address == first) + .filter(cls.second_address == second) .first() ) # ... create a new one. @@ -181,7 +182,7 @@ class Path(meta.Base): return paths @classmethod - def from_order(cls, order: "db.Order", *, google_maps: bool = False) -> "Path": + def from_order(cls, order: "db.Order", *, google_maps: bool = False) -> t.Self: """Calculate the path for an `Order` object. The path goes from the `Order.pickup_address` to the `Order.delivery_address`. diff --git a/src/velofy/db/cities.py b/src/velofy/db/cities.py index e232953..570baa6 100644 --- a/src/velofy/db/cities.py +++ b/src/velofy/db/cities.py @@ -1,6 +1,7 @@ """Provide the ORM's `City` model.""" import functools +import typing as t import folium import sqlalchemy as sa @@ -127,7 +128,7 @@ class City(meta.Base): """ return self.northeast.northing - self.southwest.northing - def clear_map(self) -> "City": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Create a new `folium.Map` object aligned with the city's viewport. The map is available via the `.map` property. Note that it is mutable diff --git a/src/velofy/db/customers.py b/src/velofy/db/customers.py index 5c852ae..7a9e4b1 100644 --- a/src/velofy/db/customers.py +++ b/src/velofy/db/customers.py @@ -1,5 +1,7 @@ """Provide the ORM's `Customer` model.""" +import typing as t + import folium import sqlalchemy as sa from sqlalchemy import orm @@ -31,7 +33,7 @@ class Customer(meta.Base): back_populates="customer", ) - def clear_map(self) -> "Customer": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Shortcut to the `...city.clear_map()` method. Returns: diff --git a/src/velofy/db/forecasts.py b/src/velofy/db/forecasts.py index 877f6fa..0f04a45 100644 --- a/src/velofy/db/forecasts.py +++ b/src/velofy/db/forecasts.py @@ -2,6 +2,7 @@ import datetime as dt import math +import typing as t import pandas as pd import sqlalchemy as sa @@ -194,7 +195,7 @@ class Forecast(meta.Base): train_horizon: int, model: str, data: pd.DataFrame, - ) -> list["db.Forecast"]: + ) -> list[t.Self]: """Convert results from the forecasting `*Model`s into `Forecast` objects. This is an alternative constructor method. diff --git a/src/velofy/db/grids.py b/src/velofy/db/grids.py index e307e96..365f7c0 100644 --- a/src/velofy/db/grids.py +++ b/src/velofy/db/grids.py @@ -71,7 +71,7 @@ class Grid(meta.Base): return round((self.side_length**2) / 1_000_000, 1) @classmethod - def gridify(cls, city: db.City, side_length: int) -> "db.Grid": + def gridify(cls, city: db.City, side_length: int) -> t.Self: """Create a fully populated `Grid` for a `city`. The `Grid` contains only `Pixel`s that have at least one @@ -126,7 +126,7 @@ class Grid(meta.Base): return grid - def clear_map(self) -> "Grid": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Shortcut to the `.city.clear_map()` method. Returns: diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index 2614719..001ef3c 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -1,6 +1,7 @@ """Provide the ORM's `Pixel` model.""" import functools +import typing as t import folium import sqlalchemy as sa @@ -149,7 +150,7 @@ class Pixel(meta.Base): .all() ) - def clear_map(self) -> "Pixel": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Shortcut to the `.city.clear_map()` method. Returns: diff --git a/src/velofy/db/restaurants.py b/src/velofy/db/restaurants.py index 5f7acbc..7936b60 100644 --- a/src/velofy/db/restaurants.py +++ b/src/velofy/db/restaurants.py @@ -1,6 +1,7 @@ """Provide the ORM's `Restaurant` model.""" import datetime as dt +import typing as t import folium import sqlalchemy as sa @@ -76,7 +77,7 @@ class Restaurant(meta.Base): """Non-literal text representation.""" return f"<{self.__class__.__name__}({self.name})>" - def clear_map(self) -> "Restaurant": # pragma: no cover + def clear_map(self) -> t.Self: # pragma: no cover """Shortcut to the `.address.city.clear_map()` method. Returns: