Repository navigation
Add type hints via a jsonpointer-stubs package - #106
Merged
Merged
Conversation
jsonpointer.py stays a single-file module. Type information is shipped as a PEP 561 stub-only package (jsonpointer-stubs) inside the same wheel and sdist. A CI job runs mypy's stubtest to keep the stubs in sync with the implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PewzpkKQeJ6P2vfXcywcMy
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The stubs-only classifier in setup.py misrepresents the distribution because it also ships the runtime jsonpointer.py module.
1 open issue
What changed in this PR
This PR adds public API type hints while preserving jsonpointer.py as a single-file runtime module.
Changes:
- Adds a
jsonpointer-stubspackage with subclass-preserving return types. - Includes the stubs in wheel and source distributions.
- Adds CI validation using
mypy.stubtestagainst the installed package.
| File | Description |
|---|---|
setup.py |
Packages the stubs and adds typing metadata. |
MANIFEST.in |
Includes stub files in source distributions. |
jsonpointer-stubs/__init__.pyi |
Defines type hints for the public API. |
.github/workflows/test.yaml |
Adds an installed-package stub validation job. |
Review effort: Balanced
The distribution ships the runtime module alongside the stubs, so 'Stubs Only' misdescribes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PewzpkKQeJ6P2vfXcywcMy
jeonsworld
pushed a commit
to jeonsworld/python-json-patch-chat
that referenced
this pull request
Nov 6, 2026
mypy reported "module is installed, but missing library stubs or py.typed marker" for jsonpatch. PEP 561 has no py.typed marker for single-file modules, so the types are shipped as a stub-only package, jsonpatch-stubs, in the same distribution, which type checkers pick up automatically. This keeps jsonpatch.py a single module without annotations. JSON documents are typed as Any, as they can be any JSON value and the module accepts arbitrary Mapping / Sequence types. Patches are typed as str | bytes | Iterable[Mapping[str, Any]]. A new CI job runs mypy's stubtest to check that the stubs agree with jsonpatch.py, and type-checks typical usage (typetests/usage.py) against the installed distribution with mypy --strict, including usage that must be rejected. Released jsonpointer versions are untyped, so pyproject.toml tells mypy to ignore that; the stubs also pass against the typed jsonpointer from stefankoegl/python-json-pointer#106. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pewzpj8LrcYUx1DeTxFCMg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds type hints for jsonpointer while keeping
jsonpointer.pya single-file module. The hints ship as a PEP 561 stub-only package,jsonpointer-stubs, inside the same wheel and sdist.Changes
jsonpointer-stubs/__init__.pyi(new): stubs for the full public API (set_pointer,resolve_pointer,pairwise,JsonPointer,EndOfList,JsonPointerException,escape/unescape,VERBOSE_EXCEPTIONS, metadata dunders).Any;JsonPointer.partsislist[str]; path segments arestr | int.join,__truediv__andfrom_partsreturnSelf, so subclasses keep their type.setup.py: ships the stubs package viapackages/package_dataand adds theTyping :: Typedclassifier.MANIFEST.in: includes the.pyifile in the sdist.mypy.stubtestagainst the installed package, so the stubs can't drift from the implementation.Testing
jsonpointer.pyandjsonpointer-stubs/__init__.pyi.python -m mypy.stubtest jsonpointerpasses, andmypy --strictresolves the stubs (e.g.JsonPointer(1)is flagged as an error).python -m unittest,flake8andtwine check --strictpass.Notes for review
Selffromtyping_extensionsto support Python 3.10. Type checkers bundle it, so it's not a runtime dependency.🤖 Generated with Claude Code
https://claude.ai/code/session_01PewzpkKQeJ6P2vfXcywcMy