Skip to content

Add type hints and mypy - #2

Merged
terapyon merged 2 commits into
mainfrom
add-type-hints
Oct 20, 2026
Merged

terapyon merged 2 commits into
mainfrom
add-type-hints

Conversation

@terapyon

@terapyon terapyon commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Adds argument and return type hints to every function and method in src, makes ruff enforce them, and checks the types with mypy in tox and CI.

Changes

  • Type hints in transform, setuphandlers and testing, using the concrete Zope/Plone classes (SetupTool, datastream, PloneSite, ...)
  • Type hints on test fixtures and helpers
  • ruff: select ANN; ignore ANN001/ANN201 in tests/
  • mypy 2.4.0 (dev dependency group): tox -e mypy and a mypy CI job; src is checked strictly, untyped Zope/Plone modules are listed one by one

Tests

All green: 13 tox environments + ruff + mypy, 51 passed / 1 xfailed, 0 skipped (with Java). No behaviour change.

🤖 Generated with Claude Code

terapyon and others added 2 commits October 20, 2026 10:16
Every function and method in src now has argument and return types.
Zope and Plone objects use their concrete classes: SetupTool for the
setup handlers, datastream in the transform, and Application,
ConfigurationMachine and PloneSite in the test layer. Fixtures and
helpers in tests are annotated too, with the classes pytest-plone uses
(PloneSite, InstallerView).

ruff now selects ANN. In tests ANN001 and ANN201 are ignored, because
test functions take untyped fixtures and return nothing. No behaviour
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mypy 2.4.0 is pinned in the "dev" dependency group (PEP 735), so the pin
does not go into the package metadata. The setup is the same as in
c2.splitter.icu.

- tox: a "mypy" environment with the Plone 6.2 dependencies on Python
  3.14 runs "mypy src tests"; it is in the envlist. tox 4.22 or later is
  required for dependency_groups.
- CI: a "mypy" job next to "lint". It needs no Java.
- [tool.mypy]: disallow_untyped_defs, check_untyped_defs,
  warn_unused_ignores, warn_redundant_casts, warn_return_any and
  warn_unused_configs. tests.* may have untyped defs. mypy_path = "src"
  with explicit_package_bases, so that mypy reads the sources and not the
  installed package, which has no py.typed. The Zope and Plone modules
  without type information are listed one by one for
  ignore_missing_imports.

Type errors found in the tests and fixed without changing what they
test: FakeRun.calls had no element type; fake_run passed **kwargs typed
as object to FakeRun, so it now takes the four keyword arguments; and
three helpers returned Any from Plone as str, so the value is now
assigned to a str variable first. src had no errors.

Checked that mypy fails when msdoc2txt is declared to return str (5
errors) and when getNonInstallableProfiles returns list[int].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@terapyon terapyon changed the title Add type hints to all functions and enforce them with ruff Add type hints and mypy Oct 20, 2026
@terapyon
terapyon merged commit ef2caf8 into main Oct 20, 2026
15 checks passed
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.

1 participant