-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Feature request: Static type support using TypedDict #167
Comments
Hi @kylebarron good suggestion. Given that the objects defined in the GeoJSON spec (RFC7946) are explicitly typed themselves, Please submit a PR if you still can; be sure to include per-key type specifications for all Thanks! |
I would like to help with this, and maybe as a first step watch/help advance someone else's source code if they've got it going.
The above attempt to initialize via a |
@rayrrr or other maintainers - Is this feature enhancement still of interest? If yes, I can work on it. Please advise! Thanks for your time. |
I never started work on this. I briefly looked into it and felt that there were issues with typed dict that would make it hard... but in Python 3.11 class Feature(TypedDict):
properties: dict
bbox: NotRequired[Tuple[float, ...]] I'd also suggest taking a look at https://github.com/developmentseed/geojson-pydantic as a reference. For example, in https://github.com/developmentseed/geojson-pydantic/blob/b20bd7ed7c3475d6df650430c864259bb246fcb0/geojson_pydantic/features.py they've implemented generics on the class MyPropertiesLayout(TypedDict):
property1: str
my_feature_type = Feature[Point, MyOwnTypedDict] |
Just a quick update. I have started to work on this feature enhancement. One of my first steps is to document the members needed for each GeoJSON object per the RFC. I will consolidate this information in the next few days. I am also looking at how to include type hinting specially in nested classes. This is where kylebarron's suggestion is likely to help. Thank you. |
Is this issue just waiting for someone to review Toblerity/Fiona#1259 or is it still open? I want to contribute but in doubt if it's already done and waiting for review. |
👋
Recent versions of Python support optional static typing, including TypedDict, a way to define the types of properties on a dictionary. I see this project already requires 3.6 or higher, and a backport of TypedDict is in
typing-extensions
for Python 3.6 and Python 3.7.I see all classes in this package currently subclass from
dict
:geojson/geojson/base.py
Line 5 in 0041e1d
This means it wouldn't be hard to add typing support, by removing the
dict
superclass and replacing it withtyping.TypedDict
(ortyping_extensions.TypedDict
for 3.6 and 3.7).I'd be happy to submit a PR, but figured I should make an issue first to discuss.
The text was updated successfully, but these errors were encountered: