Skip to content

Commit 36228a9

Browse files
committed
Replace usage of deprecated functions with current ones.
1 parent 40dbafb commit 36228a9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

geojson_pydantic/geo_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from typing import Any, Dict, Protocol
44

55

6-
class _DictProtocol(Protocol):
6+
class _ModelDumpProtocol(Protocol):
77
"""Protocol for use as the type of self in the mixin."""
88

9-
def dict(self, *, exclude_unset: bool, **args: Any) -> Dict[str, Any]:
9+
def model_dump(self, *, exclude_unset: bool, **args: Any) -> Dict[str, Any]:
1010
"""Define a dict function so the mixin knows it exists."""
1111
...
1212

@@ -15,9 +15,9 @@ class GeoInterfaceMixin:
1515
"""Mixin for __geo_interface__ on GeoJSON objects."""
1616

1717
@property
18-
def __geo_interface__(self: _DictProtocol) -> Dict[str, Any]:
18+
def __geo_interface__(self: _ModelDumpProtocol) -> Dict[str, Any]:
1919
"""GeoJSON-like protocol for geo-spatial (GIS) vector data.
2020
2121
ref: https://gist.github.com/sgillies/2217756#__geo_interface
2222
"""
23-
return self.dict(exclude_unset=True)
23+
return self.model_dump(exclude_unset=True)

geojson_pydantic/geometries.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,21 @@ def parse_geometry_obj(obj: Any) -> Geometry:
321321
raise ValueError("Missing 'type' field in geometry")
322322

323323
if obj["type"] == "Point":
324-
return Point.parse_obj(obj)
324+
return Point.model_validate(obj)
325325

326326
elif obj["type"] == "MultiPoint":
327-
return MultiPoint.parse_obj(obj)
327+
return MultiPoint.model_validate(obj)
328328

329329
elif obj["type"] == "LineString":
330-
return LineString.parse_obj(obj)
330+
return LineString.model_validate(obj)
331331

332332
elif obj["type"] == "MultiLineString":
333-
return MultiLineString.parse_obj(obj)
333+
return MultiLineString.model_validate(obj)
334334

335335
elif obj["type"] == "Polygon":
336-
return Polygon.parse_obj(obj)
336+
return Polygon.model_validate(obj)
337337

338338
elif obj["type"] == "MultiPolygon":
339-
return MultiPolygon.parse_obj(obj)
339+
return MultiPolygon.model_validate(obj)
340340

341341
raise ValueError(f"Unknown type: {obj['type']}")

tests/test_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Pointy:
174174
__geo_interface__ = {"type": "Point", "coordinates": (0.0, 0.0)}
175175

176176
feat = Feature(type="Feature", geometry=Pointy(), properties={})
177-
assert feat.geometry.dict(exclude_unset=True) == Pointy.__geo_interface__
177+
assert feat.geometry.model_dump(exclude_unset=True) == Pointy.__geo_interface__
178178

179179

180180
def test_feature_with_null_geometry():

0 commit comments

Comments
 (0)