From c556d120276adb50116ed0ea8990565a5ea1654a Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Sun, 25 Dec 2022 21:36:43 +0900 Subject: [PATCH] Fixes for mypy errors --- django-stubs/contrib/gis/gdal/geometries.pyi | 9 ++++++--- django-stubs/contrib/gis/gdal/raster/band.pyi | 9 +++------ django-stubs/contrib/gis/gdal/raster/source.pyi | 3 ++- django-stubs/contrib/gis/geoip2/base.pyi | 2 +- django-stubs/contrib/gis/geos/collections.pyi | 3 ++- django-stubs/contrib/gis/geos/factory.pyi | 4 ++-- django-stubs/contrib/gis/geos/linestring.pyi | 3 ++- django-stubs/contrib/gis/geos/point.pyi | 7 +++---- django-stubs/contrib/gis/geos/polygon.pyi | 3 ++- django-stubs/contrib/gis/measure.pyi | 2 +- django-stubs/contrib/gis/utils/layermapping.pyi | 4 ++-- 11 files changed, 26 insertions(+), 23 deletions(-) diff --git a/django-stubs/contrib/gis/gdal/geometries.pyi b/django-stubs/contrib/gis/gdal/geometries.pyi index a4aa842536..aacde98759 100644 --- a/django-stubs/contrib/gis/gdal/geometries.pyi +++ b/django-stubs/contrib/gis/gdal/geometries.pyi @@ -94,8 +94,9 @@ class Point(OGRGeometry): @property def z(self) -> float | None: ... @property + def coords(self) -> tuple[float, float] | tuple[float, float, float]: ... + @property def tuple(self) -> tuple[float, float] | tuple[float, float, float]: ... - coords: tuple[float, float] | tuple[float, float, float] class LineString(OGRGeometry): def __getitem__(self, index: int) -> tuple[float, ...]: ... @@ -119,8 +120,9 @@ class Polygon(OGRGeometry): def shell(self) -> OGRGeometry: ... exterior_ring: OGRGeometry @property + def coords(self) -> tuple[tuple[tuple[float]]]: ... + @property def tuple(self) -> tuple[tuple[tuple[float]]]: ... - coords: tuple[tuple[tuple[float]]] @property def point_count(self) -> int: ... @property @@ -133,8 +135,9 @@ class GeometryCollection(OGRGeometry): @property def point_count(self) -> int: ... @property + def coords(self) -> tuple[Any]: ... + @property def tuple(self) -> tuple[Any]: ... - coords: tuple[Any] class MultiPoint(GeometryCollection): ... class MultiLineString(GeometryCollection): ... diff --git a/django-stubs/contrib/gis/gdal/raster/band.pyi b/django-stubs/contrib/gis/gdal/raster/band.pyi index a4e2e5139e..de2bd97a58 100644 --- a/django-stubs/contrib/gis/gdal/raster/band.pyi +++ b/django-stubs/contrib/gis/gdal/raster/band.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterator -from typing import Any, Literal, overload +from typing import Any, Literal, SupportsIndex, overload from django.contrib.gis.gdal.raster.base import GDALRasterBase as GDALRasterBase @@ -36,7 +36,7 @@ class GDALBand(GDALRasterBase): @overload def color_interp(self, as_string: Literal[False] = ...) -> int: ... @overload - def color_interp(self, as_string: Literal[True] = ...) -> str: ... + def color_interp(self, as_string: Literal[True]) -> str: ... def data( self, data: Any | None = ..., @@ -46,9 +46,6 @@ class GDALBand(GDALRasterBase): as_memoryview: bool = ..., ) -> Any: ... -class BandList(list): +class BandList(list[GDALBand]): source: Any def __init__(self, source: Any) -> None: ... - def __iter__(self) -> Iterator[GDALBand]: ... - def __len__(self) -> int: ... - def __getitem__(self, index: int) -> GDALBand: ... diff --git a/django-stubs/contrib/gis/gdal/raster/source.pyi b/django-stubs/contrib/gis/gdal/raster/source.pyi index 57fecae6ca..a66e4676c7 100644 --- a/django-stubs/contrib/gis/gdal/raster/source.pyi +++ b/django-stubs/contrib/gis/gdal/raster/source.pyi @@ -1,3 +1,4 @@ +from collections.abc import Sequence from typing import Any from django.contrib.gis.gdal.driver import Driver as Driver @@ -5,7 +6,7 @@ from django.contrib.gis.gdal.raster.band import BandList as BandList from django.contrib.gis.gdal.raster.base import GDALRasterBase as GDALRasterBase from django.contrib.gis.gdal.srs import SpatialReference as SpatialReference -class TransformPoint(list): +class TransformPoint(list[Sequence[float]]): indices: dict[str, tuple[int, int]] def __init__(self, raster: GDALRaster, prop: str) -> None: ... @property diff --git a/django-stubs/contrib/gis/geoip2/base.pyi b/django-stubs/contrib/gis/geoip2/base.pyi index 90b84ccb96..8b4884238a 100644 --- a/django-stubs/contrib/gis/geoip2/base.pyi +++ b/django-stubs/contrib/gis/geoip2/base.pyi @@ -14,7 +14,7 @@ class GeoIP2: MODE_MMAP: int MODE_FILE: int MODE_MEMORY: int - cache_options: frozenset + cache_options: frozenset[int] def __init__( self, path: Path | str | None = ..., cache: int = ..., country: Any | None = ..., city: Any | None = ... ) -> None: ... diff --git a/django-stubs/contrib/gis/geos/collections.pyi b/django-stubs/contrib/gis/geos/collections.pyi index 585185a49b..7ae5de1ca0 100644 --- a/django-stubs/contrib/gis/geos/collections.pyi +++ b/django-stubs/contrib/gis/geos/collections.pyi @@ -9,8 +9,9 @@ class GeometryCollection(GEOSGeometry): def __iter__(self) -> Iterator[GEOSGeometry]: ... def __len__(self) -> int: ... @property + def coords(self) -> tuple[Any]: ... + @property def tuple(self) -> tuple[Any]: ... - coords: tuple[Any] class MultiPoint(GeometryCollection): ... class MultiLineString(LinearGeometryMixin, GeometryCollection): ... diff --git a/django-stubs/contrib/gis/geos/factory.pyi b/django-stubs/contrib/gis/geos/factory.pyi index c4426dca47..5275963e51 100644 --- a/django-stubs/contrib/gis/geos/factory.pyi +++ b/django-stubs/contrib/gis/geos/factory.pyi @@ -1,6 +1,6 @@ -from typing import IO, Any +from typing import Any, BinaryIO, TextIO from django.contrib.gis.geos.geometry import GEOSGeometry -def fromfile(file_h: str | IO) -> GEOSGeometry: ... +def fromfile(file_h: str | TextIO | BinaryIO) -> GEOSGeometry: ... def fromstr(string: str, **kwargs: Any) -> GEOSGeometry: ... diff --git a/django-stubs/contrib/gis/geos/linestring.pyi b/django-stubs/contrib/gis/geos/linestring.pyi index cd59f4dd05..fde773cab1 100644 --- a/django-stubs/contrib/gis/geos/linestring.pyi +++ b/django-stubs/contrib/gis/geos/linestring.pyi @@ -10,8 +10,9 @@ class LineString(LinearGeometryMixin, GEOSGeometry): def __iter__(self) -> Iterator[tuple[float, ...]]: ... def __len__(self) -> int: ... @property + def coords(self) -> tuple[tuple[float, ...]]: ... + @property def tuple(self) -> tuple[tuple[float, ...]]: ... - coords: tuple[tuple[float, ...]] @property def array(self) -> Any: ... @property diff --git a/django-stubs/contrib/gis/geos/point.pyi b/django-stubs/contrib/gis/geos/point.pyi index 668bf00e77..cdc40d35d4 100644 --- a/django-stubs/contrib/gis/geos/point.pyi +++ b/django-stubs/contrib/gis/geos/point.pyi @@ -23,7 +23,6 @@ class Point(GEOSGeometry): @z.setter def z(self, value: float) -> None: ... @property - def tuple(self) -> tuple[float, ...]: ... - @tuple.setter - def tuple(self, tup: Any) -> None: ... - coords: tuple[float, ...] + def coords(self) -> tuple[float, ...]: ... + @coords.setter + def coords(self, tup: Any) -> None: ... diff --git a/django-stubs/contrib/gis/geos/polygon.pyi b/django-stubs/contrib/gis/geos/polygon.pyi index f24f4cace9..8e5a3898c6 100644 --- a/django-stubs/contrib/gis/geos/polygon.pyi +++ b/django-stubs/contrib/gis/geos/polygon.pyi @@ -15,5 +15,6 @@ class Polygon(GEOSGeometry): exterior_ring: LinearRing shell: LinearRing @property + def coords(self) -> tuple[tuple[tuple[float, ...]]]: ... + @property def tuple(self) -> tuple[tuple[tuple[float, ...]]]: ... - coords: tuple[tuple[tuple[float, ...]]] diff --git a/django-stubs/contrib/gis/measure.pyi b/django-stubs/contrib/gis/measure.pyi index 16bacd9e95..422f5f3fed 100644 --- a/django-stubs/contrib/gis/measure.pyi +++ b/django-stubs/contrib/gis/measure.pyi @@ -22,7 +22,7 @@ class MeasureBase: def __isub__(self: Self, other: Self) -> Self: ... def __mul__(self, other: _NUMERIC_TYPES) -> Any: ... def __imul__(self: Self, other: _NUMERIC_TYPES) -> Self: ... - def __rmul__(self: Self, other: _NUMERIC_TYPES) -> Self: ... + def __rmul__(self: Self, other: Any) -> Self: ... def __truediv__(self: Self, other: _NUMERIC_TYPES) -> Self: ... def __itruediv__(self: Self, other: _NUMERIC_TYPES) -> Self: ... def __bool__(self) -> bool: ... diff --git a/django-stubs/contrib/gis/utils/layermapping.pyi b/django-stubs/contrib/gis/utils/layermapping.pyi index eb20798b35..f273b51368 100644 --- a/django-stubs/contrib/gis/utils/layermapping.pyi +++ b/django-stubs/contrib/gis/utils/layermapping.pyi @@ -27,7 +27,7 @@ class LayerMapping: source_srs: Any transform: Any encoding: str | None - unique: list | tuple | str | None + unique: list[str] | tuple[str] | str | None transaction_mode: Any transaction_decorator: Any def __init__( @@ -40,7 +40,7 @@ class LayerMapping: encoding: str = ..., transaction_mode: str = ..., transform: bool = ..., - unique: list | tuple | str | None = ..., + unique: list[str] | tuple[str] | str | None = ..., using: str | None = ..., ) -> None: ... def check_fid_range(self, fid_range: Any) -> Any: ...