Skip to content

Commit 1a42e03

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

9 files changed

Lines changed: 135 additions & 52 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: Any, default: Any = None, strict: bool = False) -> Any: ...
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: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import json
2+
from _typeshed import SupportsRead, SupportsWrite
3+
from collections.abc import Callable
4+
from typing import Any
5+
6+
from geojson import GeoJSON
27

38
class GeoJSONEncoder(json.JSONEncoder):
4-
def default(self, obj): ...
9+
def default(self, obj) -> GeoJSON: ...
510

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): ...
11+
def dump(
12+
obj: Any, fp: SupportsWrite[str], cls: type[json.JSONEncoder] | None = json.JSONEncoder, allow_nan: bool = False, **kwargs
13+
) -> None: ...
14+
def dumps(
15+
obj: Any, cls: type[json.JSONEncoder] | None = json.JSONEncoder, allow_nan: bool = False, ensure_ascii: bool = False, **kwargs
16+
) -> str: ...
17+
def load(
18+
fp: SupportsRead[str],
19+
cls: type[json.JSONDecoder] = json.JSONDecoder,
20+
parse_constant: Callable[[Any], None] = ...,
21+
object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance,
22+
**kwargs,
23+
) -> GeoJSON: ...
24+
def loads(
25+
s: str,
26+
cls: type[json.JSONDecoder] = json.JSONDecoder,
27+
parse_constant: Callable[[Any], None] = ...,
28+
object_hook: Callable[..., GeoJSON] = GeoJSON.to_instance,
29+
**kwargs,
30+
) -> GeoJSON: ...
1031

1132
PyGFPEncoder = GeoJSONEncoder

stubs/geojson/geojson/examples.pyi

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
from _typeshed import Incomplete
1+
from typing import Any, Literal
2+
3+
from geojson.geometry import Geometry
4+
5+
from geojson import GeoJSON
26

37
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
10-
11-
def create_simple_web_feature(o): ...
8+
id: None | int | str
9+
geometry: None | Geometry
10+
properties: dict[Literal["title", "summary", "link"], str]
11+
__geo_interface__: dict[str, Any]
12+
def __init__(
13+
self,
14+
id: None | int | str = None,
15+
geometry: None | dict[str, Any] = None,
16+
title: None | str = None,
17+
summary: None | str = None,
18+
link: None | str = None,
19+
) -> None: ...
20+
def as_dict(self) -> dict[str, Any]: ...
21+
22+
def create_simple_web_feature(o: dict[str, Any]) -> GeoJSON: ...

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 | Geometry], **extra) -> None: ...
14+
def errors(self) -> list[str] | None: ...
15+
def __getitem__(self, key) -> Feature: ...

stubs/geojson/geojson/geometry.pyi

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
1+
from collections.abc import Iterable
2+
from typing import Any
3+
14
from geojson.base import GeoJSON
25

6+
from geojson import Feature
7+
38
DEFAULT_PRECISION: int
49

510
class Geometry(GeoJSON):
6-
def __init__(self, coordinates=None, validate: bool = False, precision=None, **extra) -> None: ...
11+
def __init__(
12+
self, coordinates: None | Feature | Iterable[Any] = None, validate: bool = False, precision: None | int = None, **extra
13+
) -> None: ...
714
@classmethod
8-
def clean_coordinates(cls, coords, precision): ...
15+
def clean_coordinates(
16+
cls, coords: Geometry | tuple[Any, ...] | list[tuple[Any, ...]], precision: None | int
17+
) -> None | tuple[Any, ...] | list[tuple[Any, ...]]: ...
918

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

15-
def check_point(coord): ...
24+
def check_point(coord) -> str | None: ...
1625

1726
class Point(Geometry):
18-
def errors(self): ...
27+
def errors(self) -> list[str] | None: ...
1928

2029
class MultiPoint(Geometry):
21-
def errors(self): ...
30+
def errors(self) -> list[str] | None: ...
2231

23-
def check_line_string(coord): ...
32+
def check_line_string(coord) -> str | None: ...
2433

2534
class LineString(MultiPoint):
26-
def errors(self): ...
35+
def errors(self) -> list[str] | None: ...
2736

2837
class MultiLineString(Geometry):
29-
def errors(self): ...
38+
def errors(self) -> list[str] | None: ...
3039

31-
def check_polygon(coord): ...
40+
def check_polygon(coord) -> str | None: ...
3241

3342
class Polygon(Geometry):
34-
def errors(self): ...
43+
def errors(self) -> list[str] | None: ...
3544

3645
class MultiPolygon(Geometry):
37-
def errors(self): ...
46+
def errors(self) -> list[str] | None: ...
3847

3948
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
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.geometry import Geometry
5+
6+
from geojson import Feature, GeoJSON
7+
8+
def coords(obj: Feature | Geometry | dict[str, Any]) -> Generator[tuple[Any]]: ...
9+
def map_coords(func, obj) -> dict[str, Any]: ...
10+
def map_tuples(func, obj) -> list[tuple[float]]: ...
11+
def map_geometries(func, obj) -> GeoJSON: ...
12+
def generate_random(
13+
featureType: Literal["Point", "LineString", "Polygon"],
14+
numberVertices: int = 3,
15+
boundingBox: list[float] = [-180.0, -90.0, 180.0, 90.0],
16+
) -> Feature: ...

0 commit comments

Comments
 (0)