From d3474285280c66bf23b8c7ce4070e4a0884df02c Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Tue, 3 Dec 2024 19:51:40 +0000 Subject: [PATCH] ruff fixes --- .github/workflows/run-all-tests.yml | 2 +- pygeoif/feature.py | 5 ++--- pygeoif/functions.py | 1 + pygeoif/geometry.py | 19 ++++++------------- tox.ini | 1 + 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/run-all-tests.yml b/.github/workflows/run-all-tests.yml index 6c47bf2a..efa6c64d 100644 --- a/.github/workflows/run-all-tests.yml +++ b/.github/workflows/run-all-tests.yml @@ -96,7 +96,7 @@ jobs: - name: Linting run: | flake8 pygeoif - black --check pygeoif tests + ruff format --check pygeoif tests ruff check --no-fix pygeoif tests yamllint .github/workflows/ - name: Check complexity diff --git a/pygeoif/feature.py b/pygeoif/feature.py index 90747f29..ad498500 100644 --- a/pygeoif/feature.py +++ b/pygeoif/feature.py @@ -17,6 +17,7 @@ # # file deepcode ignore inconsistent~equality: Python 3 only """Features.""" + from typing import Any from typing import Dict from typing import Generator @@ -229,9 +230,7 @@ def __geo_interface__(self) -> GeoFeatureCollectionInterface: def _check_interface(self, other: object) -> bool: try: - return self.__geo_interface__[ - "type" - ] == other.__geo_interface__.get( # type: ignore [attr-defined] + return self.__geo_interface__["type"] == other.__geo_interface__.get( # type: ignore [attr-defined] "type", ) and len( self.__geo_interface__["features"], diff --git a/pygeoif/functions.py b/pygeoif/functions.py index 0e12b2cc..324481cf 100644 --- a/pygeoif/functions.py +++ b/pygeoif/functions.py @@ -16,6 +16,7 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # """Functions for geometries.""" + import math from itertools import groupby from itertools import zip_longest diff --git a/pygeoif/geometry.py b/pygeoif/geometry.py index ebfc472c..3c48d7dd 100644 --- a/pygeoif/geometry.py +++ b/pygeoif/geometry.py @@ -20,7 +20,6 @@ import math import warnings -from itertools import chain from typing import Any from typing import Hashable from typing import Iterable @@ -859,10 +858,8 @@ def _from_dict(cls, geo_interface: GeoInterface) -> "MultiLineString": return cls(cast(Sequence[LineType], geo_interface["coordinates"])) def _prepare_hull(self) -> Iterable[Point2D]: - return ( - (pt.x, pt.y) - for pt in chain.from_iterable(line.geoms for line in self.geoms) - ) + for geom in self.geoms: + yield from geom._prepare_hull() # noqa: SLF001 class MultiPolygon(_MultiGeometry): @@ -970,10 +967,8 @@ def _from_dict(cls, geo_interface: GeoInterface) -> "MultiPolygon": return cls(cast(Sequence[PolygonType], coords)) def _prepare_hull(self) -> Iterable[Point2D]: - return ( - (pt.x, pt.y) - for pt in chain.from_iterable(poly.exterior.geoms for poly in self.geoms) - ) + for geom in self.geoms: + yield from geom._prepare_hull() # noqa: SLF001 Geometry = Union[ @@ -1091,10 +1086,8 @@ def __geo_interface__(self) -> GeoCollectionInterface: # type: ignore [override } def _prepare_hull(self) -> Iterable[Point2D]: - return chain.from_iterable( - geom._prepare_hull() # noqa: SLF001 - for geom in self.geoms - ) + for geom in self.geoms: + yield from geom._prepare_hull() # noqa: SLF001 __all__ = [ diff --git a/tox.ini b/tox.ini index 4867526c..9a61a260 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ per-file-ignores = tests/test_feature.py: ECE001,S10,D10,S307,DALL000,PT009,T003,P103 pygeoif/*: S604 pygeoif/types.py: A003 + pygeoif/feature.py: E501 mutmut_config.py: TYP001 kwargs_ignore_function_pattern_extend = '^cast$' literal_inline_quotes = double