Skip to content

Add stubs for geojson#15816

Draft
p-vdp wants to merge 5 commits into
python:mainfrom
p-vdp:geojson
Draft

Add stubs for geojson#15816
p-vdp wants to merge 5 commits into
python:mainfrom
p-vdp:geojson

Conversation

@p-vdp
Copy link
Copy Markdown

@p-vdp p-vdp commented May 20, 2026

The package maintainer has made it clear that type annotations will not be added to the project: jazzband/geojson#235 (comment)

Used scripts/create_baseline_stubs.py to generate initial stubs and tested with tests/stubtest_third_party.py.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@p-vdp
Copy link
Copy Markdown
Author

p-vdp commented May 20, 2026

Passing:

  • python tests/runtests.py --run-stubtest stubs/geojson
  • ty check on the geojson source and tests, using these stubs via --extra-search-path

@srittau
Copy link
Copy Markdown
Collaborator

srittau commented May 21, 2026

I know that the stubs are still marked as draft, but I've had a brief look. One thing I noticed is the use of Any: In most cases, there needs to be (brief) comment of why Any was used or what types are accepted. It should also be clear, why Any has to be used instead of a "real" type. One notable exceptions where we don't require an explanation is dict[str, Any].

If you need a placeholder for "not fully typed yet", either leave out the annotation or use Incomplete (imported from _typeshed) when that's not syntactically impossible. For example, you could use Iterable[Incomplete] to mark that you know that it's an iterable, but the exact types in the iterable are to be determined. On the other, something like this is useful, if using concrete types is not possible or desirable:

def foo(x: str) -> Any: ...  # returns str if x starts with "bar:", int otherwise

@p-vdp
Copy link
Copy Markdown
Author

p-vdp commented May 21, 2026

@srittau Thanks for the quick feedback! I'll take another pass at it.

Do you have any advice for typing the coordinates parameter in the geojson.geometry module? Something like None | Feature | tuple[float, float] | Iterable[tuple[float, float]] | Iterable[Iterable[tuple[float, float]]] etc. seems too crazy and still doesn't catch deeply nested edge cases.

Or should we overload the __init__ signatures for each Geometry child class?

@srittau
Copy link
Copy Markdown
Collaborator

srittau commented May 21, 2026

I haven't looked at the type, but you could try a recursive type alias. Alternatively use Any at some depth (probably not directly as argument as that would allow completely incorrect values), and add a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants