Skip to content

Commit 8ab926c

Browse files
committed
First pass at completing all stubs
1 parent 70e561c commit 8ab926c

9 files changed

Lines changed: 141 additions & 51 deletions

File tree

stubs/geojson/geojson/__init__.pyi

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from geojson._version import __version__, __version_info__
2+
from geojson.base import GeoJSON
3+
from geojson.codec import GeoJSONEncoder, dump, dumps, load, loads
4+
from geojson.feature import Feature, FeatureCollection
5+
from geojson.geometry import GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon
6+
from geojson.utils import coords, map_coords
7+
8+
__all__ = [
9+
"dump",
10+
"dumps",
11+
"load",
12+
"loads",
13+
"GeoJSONEncoder",
14+
"coords",
15+
"map_coords",
16+
"Point",
17+
"LineString",
18+
"Polygon",
19+
"MultiLineString",
20+
"MultiPoint",
21+
"MultiPolygon",
22+
"GeometryCollection",
23+
"Feature",
24+
"FeatureCollection",
25+
"GeoJSON",
26+
"__version__",
27+
"__version_info__",
28+
]

stubs/geojson/geojson/_version.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
from _typeshed import Incomplete
2-
31
__version__: str
4-
__version_info__: Incomplete
2+
__version_info__: tuple[int, ...]

stubs/geojson/geojson/base.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
from collections.abc import Callable, Iterable
12
from typing import Any
23

34
class GeoJSON(dict[str, Any]):
4-
def __init__(self, iterable=(), **extra) -> None: ...
5-
def __getattr__(self, name): ...
5+
def __init__(self, iterable: Iterable[Any] = (), **extra) -> None: ...
6+
def __getattr__(self, name) -> Any: ...
67
def __setattr__(self, name, value) -> None: ...
78
def __delattr__(self, name) -> None: ...
89
@property
9-
def __geo_interface__(self): ...
10+
def __geo_interface__(self) -> None | GeoJSON: ...
1011
@classmethod
11-
def to_instance(cls, ob, default=None, strict: bool = False): ...
12+
def to_instance(cls, ob: None | GeoJSON, default: None | GeoJSON = None, strict: bool = False) -> GeoJSON: ...
1213
@property
13-
def is_valid(self): ...
14-
def check_list_errors(self, checkFunc, lst): ...
15-
def errors(self) -> None: ...
14+
def is_valid(self) -> bool: ...
15+
def check_list_errors(self, checkFunc: Callable[..., Any], lst: list[Any]) -> list[str]: ...
16+
def errors(self) -> list[str] | None: ...

stubs/geojson/geojson/codec.pyi

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
import json
2+
import os
3+
from _typeshed import SupportsWrite
4+
from collections.abc import Callable
5+
from typing import Any
6+
7+
from geojson import GeoJSON
28

39
class GeoJSONEncoder(json.JSONEncoder):
4-
def default(self, obj): ...
10+
def default(self, obj) -> GeoJSON: ...
511

6-
def dump(obj, fp, cls=..., allow_nan: bool = False, **kwargs): ...
7-
def dumps(obj, cls=..., allow_nan: bool = False, ensure_ascii: bool = False, **kwargs): ...
8-
def load(fp, cls=..., parse_constant=..., object_hook=..., **kwargs): ...
9-
def loads(s, cls=..., parse_constant=..., object_hook=..., **kwargs): ...
12+
def dump(
13+
obj: type[GeoJSON],
14+
fp: SupportsWrite[str],
15+
cls: type[json.JSONEncoder] | None = json.JSONEncoder,
16+
allow_nan: bool = False,
17+
**kwargs,
18+
) -> None: ...
19+
def dumps(
20+
obj: type[GeoJSON],
21+
cls: type[json.JSONEncoder] | None = json.JSONEncoder,
22+
allow_nan: bool = False,
23+
ensure_ascii: bool = False,
24+
**kwargs,
25+
) -> str: ...
26+
def load(
27+
fp: os.PathLike[Any],
28+
cls: type[json.JSONDecoder] = json.JSONDecoder,
29+
parse_constant: Callable[[Any], None] = ...,
30+
object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance,
31+
**kwargs,
32+
) -> GeoJSON: ...
33+
def loads(
34+
s: str,
35+
cls: type[json.JSONDecoder] = json.JSONDecoder,
36+
parse_constant: Callable[[Any], None] = ...,
37+
object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance,
38+
**kwargs,
39+
) -> GeoJSON: ...
1040

1141
PyGFPEncoder = GeoJSONEncoder

stubs/geojson/geojson/examples.pyi

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
from _typeshed import Incomplete
1+
from typing import Any, Literal
2+
3+
from geojson.geometry import Geometry
24

35
class SimpleWebFeature:
4-
id: Incomplete
5-
geometry: Incomplete
6-
properties: Incomplete
7-
def __init__(self, id=None, geometry=None, title=None, summary=None, link=None) -> None: ...
8-
def as_dict(self): ...
9-
__geo_interface__: Incomplete
6+
id: None | int | str
7+
geometry: None | Geometry
8+
properties: dict[Literal["title", "summary", "link"], str]
9+
__geo_interface__: dict[str, Any]
10+
def __init__(
11+
self,
12+
id: None | int | str = None,
13+
geometry: None | Geometry = None,
14+
title: None | str = None,
15+
summary: None | str = None,
16+
link: None | str = None,
17+
) -> None: ...
18+
def as_dict(self) -> dict[str, Any]: ...
1019

11-
def create_simple_web_feature(o): ...
20+
def create_simple_web_feature(o: dict[str, Any]) -> SimpleWebFeature | dict[str, Any]: ...

stubs/geojson/geojson/feature.pyi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
from typing import Any
2+
13
from geojson.base import GeoJSON
4+
from geojson.geometry import Geometry
25

36
class Feature(GeoJSON):
4-
def __init__(self, id=None, geometry=None, properties=None, **extra) -> None: ...
5-
def errors(self): ...
7+
def __init__(
8+
self, id: None | str | int = None, geometry: None | Geometry = None, properties: None | dict[str, Any] = None, **extra
9+
) -> None: ...
10+
def errors(self) -> list[str] | None: ...
611

712
class FeatureCollection(GeoJSON):
8-
def __init__(self, features, **extra) -> None: ...
9-
def errors(self): ...
10-
def __getitem__(self, key): ...
13+
def __init__(self, features: list[Feature], **extra) -> None: ...
14+
def errors(self) -> list[str] | None: ...
15+
def __getitem__(self, key) -> Feature: ...

stubs/geojson/geojson/geometry.pyi

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
1+
from typing import Any
2+
13
from geojson.base import GeoJSON
24

35
DEFAULT_PRECISION: int
46

57
class Geometry(GeoJSON):
6-
def __init__(self, coordinates=None, validate: bool = False, precision=None, **extra) -> None: ...
8+
def __init__(
9+
self,
10+
coordinates: None | tuple[Any] | list[tuple[Any]] = None,
11+
validate: bool = False,
12+
precision: None | int = None,
13+
**extra,
14+
) -> None: ...
715
@classmethod
8-
def clean_coordinates(cls, coords, precision): ...
16+
def clean_coordinates(
17+
cls, coords: Geometry | tuple[Any] | list[tuple[Any]], precision: None | int
18+
) -> None | tuple[Any] | list[tuple[Any]]: ...
919

1020
class GeometryCollection(GeoJSON):
11-
def __init__(self, geometries=None, **extra) -> None: ...
12-
def errors(self): ...
13-
def __getitem__(self, key): ...
21+
def __init__(self, geometries=..., **extra) -> None: ...
22+
def errors(self) -> list[str] | None: ...
23+
def __getitem__(self, key) -> Geometry | tuple[()] | None: ...
1424

15-
def check_point(coord): ...
25+
def check_point(coord) -> str | None: ...
1626

1727
class Point(Geometry):
18-
def errors(self): ...
28+
def errors(self) -> list[str] | None: ...
1929

2030
class MultiPoint(Geometry):
21-
def errors(self): ...
31+
def errors(self) -> list[str] | None: ...
2232

23-
def check_line_string(coord): ...
33+
def check_line_string(coord) -> str | None: ...
2434

2535
class LineString(MultiPoint):
26-
def errors(self): ...
36+
def errors(self) -> list[str] | None: ...
2737

2838
class MultiLineString(Geometry):
29-
def errors(self): ...
39+
def errors(self) -> list[str] | None: ...
3040

31-
def check_polygon(coord): ...
41+
def check_polygon(coord) -> str | None: ...
3242

3343
class Polygon(Geometry):
34-
def errors(self): ...
44+
def errors(self) -> list[str] | None: ...
3545

3646
class MultiPolygon(Geometry):
37-
def errors(self): ...
47+
def errors(self) -> list[str] | None: ...
3848

3949
class Default: ...

stubs/geojson/geojson/mapping.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
GEO_INTERFACE_MARKER: str
1+
from typing import Any, Literal
22

3-
def is_mapping(obj): ...
4-
def to_mapping(obj): ...
3+
GEO_INTERFACE_MARKER: Literal["__geo_interface__"]
4+
5+
def is_mapping(obj) -> bool: ...
6+
def to_mapping(obj) -> dict[str, Any]: ...

stubs/geojson/geojson/utils.pyi

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Generator
2+
from typing import Any, Literal
33

4-
def coords(obj) -> Generator[Incomplete, Incomplete]: ...
5-
def map_coords(func, obj): ...
6-
def map_tuples(func, obj): ...
7-
def map_geometries(func, obj): ...
8-
def generate_random(featureType, numberVertices: int = 3, boundingBox=[-180.0, -90.0, 180.0, 90.0]): ...
4+
from geojson import Feature, GeoJSON
5+
from geojson.geometry import Geometry
6+
7+
def coords(obj: Feature | Geometry) -> Generator[tuple[Any]]: ...
8+
def map_coords(func, obj) -> list[tuple[float]]: ...
9+
def map_tuples(func, obj) -> list[tuple[float]]: ...
10+
def map_geometries(func, obj) -> GeoJSON: ...
11+
def generate_random(
12+
featureType: Literal["Point", "LineString", "Polygon"],
13+
numberVertices: int = 3,
14+
boundingBox: list[float] = [-180.0, -90.0, 180.0, 90.0],
15+
) -> Feature: ...

0 commit comments

Comments
 (0)