Skip to content

Add type hints via a jsonpointer-stubs package - #106

Merged
stefankoegl merged 2 commits into
masterfrom
claude/upbeat-feynman-ew7rv3
Nov 2, 2026
Merged

stefankoegl merged 2 commits into
masterfrom
claude/upbeat-feynman-ew7rv3

Conversation

@stefankoegl

@stefankoegl stefankoegl commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Adds type hints for jsonpointer while keeping jsonpointer.py a 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).
    • JSON documents are Any; JsonPointer.parts is list[str]; path segments are str | int.
    • join, __truediv__ and from_parts return Self, so subclasses keep their type.
  • setup.py: ships the stubs package via packages/package_data and adds the Typing :: Typed classifier.
  • MANIFEST.in: includes the .pyi file in the sdist.
  • CI: new "Check type stubs" job runs mypy.stubtest against the installed package, so the stubs can't drift from the implementation.

Testing

  • Built the wheel and sdist; both contain jsonpointer.py and jsonpointer-stubs/__init__.pyi.
  • Installed the wheel in a clean venv: python -m mypy.stubtest jsonpointer passes, and mypy --strict resolves the stubs (e.g. JsonPointer(1) is flagged as an error).
  • python -m unittest, flake8 and twine check --strict pass.

Notes for review

  • The stubs import Self from typing_extensions to 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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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-stubs package with subclass-preserving return types.
  • Includes the stubs in wheel and source distributions.
  • Adds CI validation using mypy.stubtest against 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

Comment thread setup.py Resolved
@coveralls

coveralls commented Nov 2, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 97.714%. remained the same — claude/upbeat-feynman-ew7rv3 into master

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
@stefankoegl
stefankoegl merged commit 717c557 into master Nov 2, 2026
14 checks passed
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
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.

4 participants