From 1f8ecb0fd3c8abe3650fe9cf414fe549d364d2cc Mon Sep 17 00:00:00 2001 From: Austin Raney Date: Fri, 26 Jul 2024 11:02:40 -0400 Subject: [PATCH] chore: improve / modernize type hints --- python/hypy/hydrolocation/hydrolocation.py | 2 +- python/hypy/hydrolocation/nwis_location.py | 12 +++++++----- python/hypy/nexus.py | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/python/hypy/hydrolocation/hydrolocation.py b/python/hypy/hydrolocation/hydrolocation.py index ee63a8f..5d4066d 100644 --- a/python/hypy/hydrolocation/hydrolocation.py +++ b/python/hypy/hydrolocation/hydrolocation.py @@ -74,7 +74,7 @@ def realized_nexus(self) -> str: return self._realized_nexus @property - def geometry(self) -> Point | Tuple: + def geometry(self) -> Point | tuple[float, float]: """ Geometric coordinates of the location as a `Point` or two-Tuple """ diff --git a/python/hypy/hydrolocation/nwis_location.py b/python/hypy/hydrolocation/nwis_location.py index 8fcb76b..016b427 100644 --- a/python/hypy/hydrolocation/nwis_location.py +++ b/python/hypy/hydrolocation/nwis_location.py @@ -1,4 +1,6 @@ -from typing import Union, Tuple, TYPE_CHECKING +from __future__ import annotations + +from typing import Tuple, TYPE_CHECKING from hydrotools import nwis_client from hypy.hydrolocation import HydroLocation, HydroLocationType @@ -15,7 +17,7 @@ class NWISLocation(HydroLocation): def __init__(self, station_id: str, realized_nexus: str, - shape: Union['Point', Tuple] = None, + shape: Point | Tuple = None, referenced_position = None, #TODO implement indirect position? ): """ @@ -42,9 +44,9 @@ def station_id(self) -> str: return self._station_id def get_data(self, - start: Union[ str, 'datetime', 'datetime64', 'Timestamp', None ] = None, - end: Union[ str, 'datetime', 'datetime64', 'Timestamp', None ] = None - ) -> 'DataFrame': + start: str | datetime | datetime64 | Timestamp | None = None, + end: str | datetime | datetime64 | Timestamp | None = None + ) -> DataFrame: """ Get observation data from nwis """ diff --git a/python/hypy/nexus.py b/python/hypy/nexus.py index d79b17a..4df7cd9 100644 --- a/python/hypy/nexus.py +++ b/python/hypy/nexus.py @@ -1,7 +1,12 @@ -from typing import List, Optional, Tuple, TYPE_CHECKING, Union +from __future__ import annotations + +from typing import TYPE_CHECKING + +from .catchment import Catchment if TYPE_CHECKING: - from .catchment import Catchment, Catchments_Collection + from .catchment import Catchments_Collection + from .hydrolocation.hydrolocation import HydroLocation class Nexus(): """ @@ -11,9 +16,9 @@ class Nexus(): def __init__(self, nexus_id: str, - hydro_location, - receiving_catchments: 'Catchments_Collection' = tuple(), - contributing_catchments: 'Catchments_Collection' = tuple()): + hydro_location: HydroLocation, + receiving_catchments: Catchments_Collection = tuple(), + contributing_catchments: Catchments_Collection = tuple()): """ Set the nexus identity and params @@ -44,7 +49,7 @@ def id(self) -> str: return self._id @property - def receiving_catchments (self) -> Tuple['Catchment', ...]: + def receiving_catchments (self) -> tuple[Catchment, ...]: """Tuple of Catchment object(s) receiving water from nexus Returns @@ -55,7 +60,7 @@ def receiving_catchments (self) -> Tuple['Catchment', ...]: return self._receiving_catchments @property - def contributing_catchments (self) -> Tuple['Catchment', ...]: + def contributing_catchments (self) -> tuple[Catchment, ...]: """Tuple of Catchment object(s) contributing water to nexus Returns