Skip to content

Add stubs for geojson - #15816

Merged
srittau merged 10 commits into
python:mainfrom
p-vdp:geojson
Jul 29, 2026
Merged

Add stubs for geojson#15816
srittau merged 10 commits into
python:mainfrom
p-vdp:geojson

Conversation

@p-vdp

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

Copy link
Copy Markdown
Contributor

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

This comment has been minimized.

@p-vdp

p-vdp commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

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

srittau commented May 21, 2026

Copy link
Copy Markdown
Collaborator

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

p-vdp commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@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

srittau commented May 21, 2026

Copy link
Copy Markdown
Collaborator

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.

@github-actions

This comment has been minimized.

@p-vdp
p-vdp marked this pull request as ready for review May 27, 2026 16:21
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@p-vdp

p-vdp commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

@srittau This PR is ready for a review. Thanks!

@p-vdp

p-vdp commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@srittau This has been open for a couple months. Is there more that needs to be done before merging?

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for the delay. Looks mostly good, a few small remarks below. Please also update this branch, since I think there's a merge race: You probably need to replace NoReturn with Never.

Comment thread stubs/geojson/@tests/stubtest_allowlist.txt Outdated
Comment thread stubs/geojson/geojson/base.pyi Outdated
Comment thread stubs/geojson/geojson/geometry.pyi Outdated
@github-actions

This comment has been minimized.

@p-vdp
p-vdp requested a review from srittau July 29, 2026 20:17
@github-actions

This comment has been minimized.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more thing.

Comment thread stubs/geojson/geojson/codec.pyi Outdated
Comment thread stubs/geojson/geojson/codec.pyi Outdated
Comment thread stubs/geojson/geojson/codec.pyi Outdated
Co-authored-by: Sebastian Rittau <sebastian.rittau@zfutura.de>
@github-actions

Copy link
Copy Markdown
Contributor

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

@p-vdp
p-vdp requested a review from srittau July 29, 2026 21:34
@srittau
srittau merged commit 4b150ae into python:main Jul 29, 2026
59 checks passed
@p-vdp

p-vdp commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@srittau Thanks!

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