diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 223f0b415e45..60e8272c13ff 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -40,6 +40,7 @@ "stubs/Flask-SocketIO", "stubs/fpdf2", "stubs/gdb", + "stubs/geojson", "stubs/geopandas", "stubs/google-cloud-ndb", "stubs/grpcio-channelz/grpc_channelz/v1", diff --git a/stubs/geojson/@tests/stubtest_allowlist.txt b/stubs/geojson/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..8b576cfab81d --- /dev/null +++ b/stubs/geojson/@tests/stubtest_allowlist.txt @@ -0,0 +1,2 @@ +geojson +geojson.examples.SimpleWebFeature.__geo_interface__ diff --git a/stubs/geojson/METADATA.toml b/stubs/geojson/METADATA.toml new file mode 100644 index 000000000000..f719694fc557 --- /dev/null +++ b/stubs/geojson/METADATA.toml @@ -0,0 +1,2 @@ +version = "3.2.*" +upstream-repository = "https://github.com/jazzband/geojson" diff --git a/stubs/geojson/geojson/__init__.pyi b/stubs/geojson/geojson/__init__.pyi new file mode 100644 index 000000000000..a022f4f97930 --- /dev/null +++ b/stubs/geojson/geojson/__init__.pyi @@ -0,0 +1,28 @@ +from geojson._version import __version__, __version_info__ +from geojson.base import GeoJSON +from geojson.codec import GeoJSONEncoder, dump, dumps, load, loads +from geojson.feature import Feature, FeatureCollection +from geojson.geometry import GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon +from geojson.utils import coords, map_coords + +__all__ = [ + "dump", + "dumps", + "load", + "loads", + "GeoJSONEncoder", + "coords", + "map_coords", + "Point", + "LineString", + "Polygon", + "MultiLineString", + "MultiPoint", + "MultiPolygon", + "GeometryCollection", + "Feature", + "FeatureCollection", + "GeoJSON", + "__version__", + "__version_info__", +] diff --git a/stubs/geojson/geojson/_version.pyi b/stubs/geojson/geojson/_version.pyi new file mode 100644 index 000000000000..fd947dd9c0e2 --- /dev/null +++ b/stubs/geojson/geojson/_version.pyi @@ -0,0 +1,2 @@ +__version__: str +__version_info__: tuple[int, ...] diff --git a/stubs/geojson/geojson/base.pyi b/stubs/geojson/geojson/base.pyi new file mode 100644 index 000000000000..64da6b2828c9 --- /dev/null +++ b/stubs/geojson/geojson/base.pyi @@ -0,0 +1,16 @@ +from collections.abc import Callable, Iterable +from typing import Any + +class GeoJSON(dict[str, Any]): + def __init__(self, iterable: Iterable[Any] = (), **extra) -> None: ... + def __getattr__(self, name) -> Any: ... + def __setattr__(self, name, value) -> None: ... + def __delattr__(self, name) -> None: ... + @property + def __geo_interface__(self) -> None | GeoJSON: ... + @classmethod + def to_instance(cls, ob: Any, default: Any = None, strict: bool = False) -> Any: ... + @property + def is_valid(self) -> bool: ... + def check_list_errors(self, checkFunc: Callable[..., Any], lst: list[Any]) -> list[str]: ... + def errors(self) -> list[str] | None: ... diff --git a/stubs/geojson/geojson/codec.pyi b/stubs/geojson/geojson/codec.pyi new file mode 100644 index 000000000000..2c052c9aecc9 --- /dev/null +++ b/stubs/geojson/geojson/codec.pyi @@ -0,0 +1,32 @@ +import json +from _typeshed import SupportsRead, SupportsWrite +from collections.abc import Callable +from typing import Any + +from geojson import GeoJSON + +class GeoJSONEncoder(json.JSONEncoder): + def default(self, obj) -> GeoJSON: ... + +def dump( + obj: Any, fp: SupportsWrite[str], cls: type[json.JSONEncoder] | None = json.JSONEncoder, allow_nan: bool = False, **kwargs +) -> None: ... +def dumps( + obj: Any, cls: type[json.JSONEncoder] | None = json.JSONEncoder, allow_nan: bool = False, ensure_ascii: bool = False, **kwargs +) -> str: ... +def load( + fp: SupportsRead[str], + cls: type[json.JSONDecoder] = json.JSONDecoder, + parse_constant: Callable[[Any], None] = ..., + object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance, + **kwargs, +) -> GeoJSON: ... +def loads( + s: str, + cls: type[json.JSONDecoder] = json.JSONDecoder, + parse_constant: Callable[[Any], None] = ..., + object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance, + **kwargs, +) -> GeoJSON: ... + +PyGFPEncoder = GeoJSONEncoder diff --git a/stubs/geojson/geojson/examples.pyi b/stubs/geojson/geojson/examples.pyi new file mode 100644 index 000000000000..144a2e2d7ad3 --- /dev/null +++ b/stubs/geojson/geojson/examples.pyi @@ -0,0 +1,21 @@ +from typing import Any, Literal + +from geojson import GeoJSON +from geojson.geometry import Geometry + +class SimpleWebFeature: + id: None | int | str + geometry: None | Geometry + properties: dict[Literal["title", "summary", "link"], str] + __geo_interface__: dict[str, Any] + def __init__( + self, + id: None | int | str = None, + geometry: None | dict[str, Any] = None, + title: None | str = None, + summary: None | str = None, + link: None | str = None, + ) -> None: ... + def as_dict(self) -> dict[str, Any]: ... + +def create_simple_web_feature(o: dict[str, Any]) -> GeoJSON: ... diff --git a/stubs/geojson/geojson/feature.pyi b/stubs/geojson/geojson/feature.pyi new file mode 100644 index 000000000000..623168b552a7 --- /dev/null +++ b/stubs/geojson/geojson/feature.pyi @@ -0,0 +1,15 @@ +from typing import Any + +from geojson.base import GeoJSON +from geojson.geometry import Geometry + +class Feature(GeoJSON): + def __init__( + self, id: None | str | int = None, geometry: None | Geometry = None, properties: None | dict[str, Any] = None, **extra + ) -> None: ... + def errors(self) -> list[str] | None: ... + +class FeatureCollection(GeoJSON): + def __init__(self, features: list[Feature | Geometry], **extra) -> None: ... + def errors(self) -> list[str] | None: ... + def __getitem__(self, key) -> Feature: ... diff --git a/stubs/geojson/geojson/geometry.pyi b/stubs/geojson/geojson/geometry.pyi new file mode 100644 index 000000000000..122afa69df8d --- /dev/null +++ b/stubs/geojson/geojson/geometry.pyi @@ -0,0 +1,47 @@ +from collections.abc import Iterable +from typing import Any + +from geojson import Feature +from geojson.base import GeoJSON + +DEFAULT_PRECISION: int + +class Geometry(GeoJSON): + def __init__( + self, coordinates: None | Feature | Iterable[Any] = None, validate: bool = False, precision: None | int = None, **extra + ) -> None: ... + @classmethod + def clean_coordinates( + cls, coords: Geometry | tuple[Any, ...] | list[tuple[Any, ...]], precision: None | int + ) -> None | tuple[Any, ...] | list[tuple[Any, ...]]: ... + +class GeometryCollection(GeoJSON): + def __init__(self, geometries=..., **extra) -> None: ... + def errors(self) -> list[str] | None: ... + def __getitem__(self, key) -> Geometry | tuple[()] | None: ... + +def check_point(coord) -> str | None: ... + +class Point(Geometry): + def errors(self) -> list[str] | None: ... + +class MultiPoint(Geometry): + def errors(self) -> list[str] | None: ... + +def check_line_string(coord) -> str | None: ... + +class LineString(MultiPoint): + def errors(self) -> list[str] | None: ... + +class MultiLineString(Geometry): + def errors(self) -> list[str] | None: ... + +def check_polygon(coord) -> str | None: ... + +class Polygon(Geometry): + def errors(self) -> list[str] | None: ... + +class MultiPolygon(Geometry): + def errors(self) -> list[str] | None: ... + +class Default: ... diff --git a/stubs/geojson/geojson/mapping.pyi b/stubs/geojson/geojson/mapping.pyi new file mode 100644 index 000000000000..d9b0e4900ebb --- /dev/null +++ b/stubs/geojson/geojson/mapping.pyi @@ -0,0 +1,6 @@ +from typing import Any, Literal + +GEO_INTERFACE_MARKER: Literal["__geo_interface__"] + +def is_mapping(obj) -> bool: ... +def to_mapping(obj) -> dict[str, Any]: ... diff --git a/stubs/geojson/geojson/utils.pyi b/stubs/geojson/geojson/utils.pyi new file mode 100644 index 000000000000..296432227e8c --- /dev/null +++ b/stubs/geojson/geojson/utils.pyi @@ -0,0 +1,15 @@ +from collections.abc import Generator +from typing import Any, Literal + +from geojson import Feature, GeoJSON +from geojson.geometry import Geometry + +def coords(obj: Feature | Geometry | dict[str, Any]) -> Generator[tuple[Any]]: ... +def map_coords(func, obj) -> dict[str, Any]: ... +def map_tuples(func, obj) -> list[tuple[float]]: ... +def map_geometries(func, obj) -> GeoJSON: ... +def generate_random( + featureType: Literal["Point", "LineString", "Polygon"], + numberVertices: int = 3, + boundingBox: list[float] = [-180.0, -90.0, 180.0, 90.0], +) -> Feature: ...