Skip to content

Commit

Permalink
Fix typing for pygeoif 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Apr 2, 2024
1 parent 469c26e commit aeae349
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ repos:
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [pygeoif, arrow]
additional_dependencies: [pygeoif>=1.4, arrow]
# - repo: https://github.com/Lucas-C/pre-commit-hooks-markup
# rev: v1.0.1
# hooks:
Expand Down
19 changes: 12 additions & 7 deletions fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from pygeoif.factories import shape
from pygeoif.types import GeoCollectionType
from pygeoif.types import GeoType
from pygeoif.types import PointType
from pygeoif.types import Point2D
from pygeoif.types import Point3D

from fastkml import config
from fastkml.base import _BaseObject
Expand Down Expand Up @@ -146,7 +147,7 @@ def geometry(self) -> Optional[AnyGeometryType]:

def _etree_coordinates(
self,
coordinates: Sequence[PointType],
coordinates: Union[Sequence[Point2D], Sequence[Point3D]],
precision: Optional[int],
) -> Element:
element = cast(
Expand Down Expand Up @@ -176,7 +177,7 @@ def _get_coordinates(
ns: str,
element: Element,
strict: bool,
) -> List[PointType]:
) -> Union[List[Point2D], List[Point3D]]:
"""
Get coordinates from element.
Expand All @@ -195,9 +196,8 @@ def _get_coordinates(
except AttributeError:
return []
try:
return [
cast(PointType, tuple(float(c) for c in latlon.split(",")))
for latlon in latlons
return [ # type: ignore[return-value]
tuple(float(c) for c in latlon.split(",")) for latlon in latlons
]
except ValueError as error:
handle_invalid_geometry_error(
Expand Down Expand Up @@ -302,7 +302,12 @@ def etree_element(
element = super().etree_element(precision=precision, verbosity=verbosity)
assert isinstance(self.geometry, geo.Point)
coords = self.geometry.coords
element.append(self._etree_coordinates(coords, precision=precision))
element.append(
self._etree_coordinates(
coords, # type: ignore[arg-type]
precision=precision,
),
)
return element

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion fastkml/kml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2023 Christian Ledermann
# Copyright (C) 2012-2024 Christian Ledermann
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
]
dependencies = [
"arrow",
"pygeoif>=1.1",
"pygeoif>=1.4",
"typing-extensions>4",
]
description = "Fast KML processing in python"
Expand Down

0 comments on commit aeae349

Please sign in to comment.