Repository navigation
Add type hints and mypy - #2
Merged
Merged
Conversation
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>
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 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
transform,setuphandlersandtesting, using the concrete Zope/Plone classes (SetupTool,datastream,PloneSite, ...)ANN; ignoreANN001/ANN201intests/tox -e mypyand amypyCI job;srcis checked strictly, untyped Zope/Plone modules are listed one by oneTests
All green: 13 tox environments + ruff + mypy, 51 passed / 1 xfailed, 0 skipped (with Java). No behaviour change.
🤖 Generated with Claude Code