Skip to content

Commit

Permalink
Typing for Python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalrussell committed Nov 13, 2023
1 parent 51c779f commit 263ced1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/snkit/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import geopandas
import numpy as np
import numpy.typing as npt
import pandas
import pyproj
import shapely.errors
Expand Down Expand Up @@ -643,7 +644,7 @@ def matching_gdf_from_geoms(gdf: GeoDataFrame, geoms: List[Geometry]) -> GeoData

def geoms_to_array(
geoms: List[Geometry],
) -> np.ndarray[List[int], Geometry]:
) -> npt.ArrayLike:
geom_arr = np.empty(len(geoms), dtype="object")
geom_arr[:] = geoms

Expand Down Expand Up @@ -867,7 +868,7 @@ def split_line(
line: LineString,
points: Union[Point, MultiPoint],
tolerance: Optional[Number] = 1e-9,
) -> list[LineString]:
) -> List[LineString]:
"""Split line at point or multipoint, within some tolerance"""
to_split = snap_line(line, points, tolerance)
# when the splitter is a self-intersection point, shapely splits in
Expand All @@ -881,7 +882,9 @@ def split_line(


def snap_line(
line: LineString, points: Point | MultiPoint, tolerance: Optional[Number] = 1e-9
line: LineString,
points: Union[Point, MultiPoint],
tolerance: Optional[Number] = 1e-9,
) -> LineString:
"""Snap a line to points within tolerance, inserting vertices as necessary"""
if points.geom_type == "Point":
Expand Down Expand Up @@ -958,7 +961,7 @@ def set_precision(geom: Geometry, precision: int) -> Geometry:

def to_networkx(
network: Network, directed: bool = False, weight_col: Optional[str] = None
) -> nx.Graph | nx.DiGraph:
) -> Union[nx.Graph, nx.DiGraph]:
"""Return a networkx graph"""
if not USE_NX:
raise ImportError("No module named networkx")
Expand Down
2 changes: 1 addition & 1 deletion src/snkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from typing import Any


def tqdm_standin(iterator: Iterator[Any], *_: Any, **__: Any) -> Iterator[Any]:
def tqdm_standin(iterator: "Iterator[Any]", *_: Any, **__: Any) -> "Iterator[Any]":
"""Alternative to tqdm, with no progress bar - ignore any arguments after the first"""
return iterator

0 comments on commit 263ced1

Please sign in to comment.