Skip to content

Typed package: ship py.typed in both wheels and put type hints on every public class and function - #481

Merged
tae898 merged 1 commit into
mainfrom
feat/476-py-typed
Nov 24, 2026
Merged

tae898 merged 1 commit into
mainfrom
feat/476-py-typed

Conversation

@tae898

@tae898 tae898 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Both wheels ship a py.typed marker (PEP 561), and every public class and function has type hints, so editors and type checkers read arcadedb as a typed package.

  • src/arcadedb/py.typed is listed as package data in both package definitions (pyproject.toml for arcadedb-jvm, native/wheel/pyproject.toml for arcadedb). I built both wheels the way CI does (native with native/wheel/build_wheel.py and the library of the main wheel, JVM with uv build of the package definition without jars): each lists arcadedb/py.typed.
  • Public callables without hints: 78 had no return hint and 107 had a parameter without one. Now all 258 functions and methods of the public modules have a return hint and all 469 parameters have one (counted by AST). The 106 additions are hints only. Any stands for what the JVM or the native library hands over, run_in_transaction has a TypeVar so the result keeps its type, and forward references use TYPE_CHECKING imports, so nothing new is imported at run time.
  • No stub file: every public name is defined in a .py file that carries its hints. The native classes under arcadedb._native are private and are returned under the public names (Database and the rest), so one set of hints serves both builds.

mypy, laptop, run once with uv run --with mypy (no CI job: the repo has no type checker configured, so I did not add one): 66 error lines on main, 65 on this branch. Annotating a function makes mypy check its body, so the hints surfaced a few findings in bodies it had skipped; I fixed those (four declarations got a type, run_in_transaction ends with an explicit return None for retries < 0, which fell off the end before, and four call sites in _native/database.py that pass a NativeDatabase where Database is named carry a type: ignore). What remains is older code: the jpype = None fallbacks, private dicts without a declared type, and the native layer's own classes. A CI type check would need those cleaned first, so it is a separate step.

Related issues

Closes #476

Docs

README.md lists the typed package under "What is included". No docs page describes typing.

Milestone

27.1.1. The change is additive and does not touch behavior, but it edits 16 modules (hints, one explicit return None, four declared types), which is more than I call small for the 26.12.1 cut.

Release note draft

Both packages now ship a py.typed marker and type hints on every public class and function, so editors and type checkers see arcadedb as typed.

Tests

tests/test_typed_package.py, run by both builds: the marker is in the installed package, both package definitions list it, every public callable of arcadedb.__all__ and arcadedb.aio.AsyncDatabase has hints on every parameter and a return hint, and the entry points name the Database type. tests/test_wheel_packages.py checks that the JVM build ships the marker. Local run on the main wheels of 2026-11-24 with this branch's Python files laid over them (laptop): 436 passed on the JVM build for the typing tests and 18 other files that exercise the touched modules, 402 passed on the native build, with 21 skips (tests that tests/conftest.py marks as not applicable on native) and 4 errors (test_vector.py fixtures that import jpype, which the native wheel does not have; the parity runner does not run those).

Checklist

  • A regression test fails on the old code and passes on the new
  • The test suite that the change can affect passes
  • uvx pre-commit run --files <changed files> passes

…ry public class and function

Neither wheel had a py.typed marker, so an editor or a type checker treated arcadedb as untyped even where the code had hints (PEP 561).
The marker is a package-data entry in both package definitions (pyproject.toml for arcadedb-jvm, native/wheel/pyproject.toml for
arcadedb): setuptools ships nothing that is not listed.

The public callables had 180 of 258 return hints and 362 of 469 parameter hints; now 258 of 258 and 469 of 469 (modules without a
leading underscore, counted by AST). The 106 additions are hints only, with Any for what the JVM or the native library hands over
(java_* parameters, Java records) and a TypeVar on run_in_transaction so the result keeps its type. Forward references use
TYPE_CHECKING imports, so nothing new is imported at run time. Code that mypy now checks changed shape without changing behavior: four declarations got a type
(server._java_server, Database._async_executors, ResultSet._facets, a stats dict), and run_in_transaction ends with an explicit "return None" for retries < 0, which fell off the end before.

No stub file: every public name is defined in a .py file that carries its hints. The native layer (arcadedb._native) is private; its
database class has the Database surface and is returned under the name Database, so the hints name Database for both builds. The
four call sites in _native/database.py that pass a NativeDatabase to a function that names Database carry a type: ignore for that.

Tests (tests/test_typed_package.py, both builds): the marker is in the installed package, both package definitions list it, every
public callable of arcadedb.__all__ and arcadedb.aio.AsyncDatabase has hints on every parameter and a return hint, and the entry points
name the Database type. tests/test_wheel_packages.py checks that the JVM build ships the marker. Built the way CI builds them (native:
native/wheel/build_wheel.py with the library of the main wheel; JVM: uv build of the package definition without jars), both wheels list
arcadedb/py.typed.

mypy (laptop, once, no CI job: the repo has no type checker configured): 66 error lines before, 65 after, none of the new ones from the
hints (new findings in bodies that mypy now checks were fixed); what remains is older code in private modules and the "jpype = None"
fallbacks.
@tae898 tae898 added this to the 27.1.1 milestone Nov 24, 2026
@tae898 tae898 added the enhancement New feature or request label Nov 24, 2026
@tae898 tae898 self-assigned this Nov 24, 2026
@tae898 tae898 modified the milestones: 27.1.1, 26.12.1 Nov 24, 2026
@tae898
tae898 merged commit 4e41bb9 into main Nov 24, 2026
24 checks passed
@tae898
tae898 deleted the feat/476-py-typed branch November 24, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Neither wheel ships py.typed or stubs

1 participant