-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/types are not flagged by static type checking #171
base: main
Are you sure you want to change the base?
Hotfix/types are not flagged by static type checking #171
Conversation
dear @frank-hulo Thanks for the PR. Sadly
from geojson_pydantic.geometries import _GeometryBase
from geojson_pydantic.types import Position
from typing import Any, Literal
class Point(_GeometryBase):
"""Point Model"""
type: Literal["Point"] = "Point"
coordinates: Position
def __wkt_coordinates__(self, coordinates: Any, force_z: bool) -> str:
"""return WKT coordinates."""
pass
@property
def has_z(self):
"""Checks if any coordinate has a Z value."""
pass
invalid_point_geometry = {"coordinates": [0, 0]}
Point.model_validate(invalid_point_geometry) # This should fail
# But it doesn't
>> Point(bbox=None, type='Point', coordinates=Position2D(longitude=0.0, latitude=0.0)) We choose this to make sure geojson models validation was For the second point I'm not quite sure to see the
For |
Thank you for the swift response. Good to understand the history, and just to understand your requirements:
|
invalid_point_geometry = {"coordinates": [0, 0]}
valid_point_geometry = {"coordinates": [0, 0], type="Point"}
Point.model_validate(invalid_point_geometry) # This should fail
Point.model_validate(valid_point_geometry ) # This should pass
Point(coordinates= [0, 0]) # this should pass yeah, We understand when |
This is my first PR on this repo, for me the contributing guidelines are not entirely clear, but will check the remakrs.
This pull request includes updates to the
geojson_pydantic/geometries.py
file to improve type consistency and string formatting. The most important changes include setting default values fortype
fields in geometry models.Reason for this update is mitigate not every time required to define the type and model init. E.g. Point(type="Point", coordinates=(0,1)). This is flagged by strict type checkers the only valid method.
Improvements to type consistency:
geojson_pydantic/geometries.py
: Set default values fortype
fields inPoint
,MultiPoint
,LineString
,MultiLineString
,Polygon
,MultiPolygon
, andGeometryCollection
models. [1] [2] [3] [4] [5] [6] [7]Improvements to string formatting:
geojson_pydantic/geometries.py
: Updated string formatting in thewkt
method ofGeometryCollection
to use double quotes for consistency.