Install dependencies
uv sync --all-groupsuv run isort ./src ./tests
uv run black ./src ./testsBoth implementation and documentation are tested with pytest and test passage is enforced in the ci. Validate that your code does not introduce regressions by running the test suite locally.
uv run pytest --cov=src/puuid/ testsuv run pytest --markdown-docs --markdown-docs-syntax=superfences docs/Generate the html coverage report. The command creates a folder htmlcov with an index.html as landing page.
uv run coverage htmlServe the documentation for easy local development.
uv run mkdocs serve -f docs/mkdocs.ymlBuild the documentation.
uv run mkdocs build -f docs/mkdocs.ymlRun static analysis with:
uv run ruff check src tests
uv run mypy src tests
uv run basedpyright src tests- Docstrings use numpydoc style
- Use Python 3.14 type hints everywhere (including tests).
- Try to keep the types as narrow as possible
- Avoid
Any,TypeVar(unless truly needed for variance),cast, andtype: ignorewhere possible. - Prefer
collections.abc(Iterable,Mapping,Callable, …) overtypingaliases. - avoid using
objectfor annotations - avoid using
castfor annotations - Try to use
StrEnumorLiteraltypes where possible and limitstrusage if the content can be known in advance. - the
__init__method of a class should be annotated with types for all arguments (exceptself) and in addition annotate the return typeNone dictis a generic type and requires two type arguments. In most cases aTypedDictshould be preferred over usingdict. Asdictitself is type invariant, it should generally be avoided as an input argument for a function -collections.abc.Mapping(being covariant) is a much better fit.- No need do
from __future__ import annotations, we are already on the newest stable 3.14 release, to the contrary - using this import will eagerly evaluate type annotations and makes forward references awkward (they'd require strings for the types) - Do not use strings for types, they are lazily evaluated in 3.14, which allows us to use the classes directly (even with forward declarations)
- Avoid using
typing.TypeGuard,typing.TypeIs(introduced in 3.13) is almost always a superior drop-in replacement
- Avoid nested function definitions except when necessary (e.g. decorators).
- Use
pathlib.Pathinstead ofos.path. - Do not concatenate strings with
+; use f-strings instead. - Avoid hard coding class names as string for the
__repr__and__str__methods. Extract the string from the class directly, so if we ever decide to rename the class we do not forget about strings left somewhere. - Try to keep the body of functions manageable in size (target below 20 lines), you should separate logical blocks out into helper functions (even if they are only used once) to achieve this.
- Avoid reassigning to the same variable multiple times. It is ok to update a collection (e.g. list), but full on reassignments should be kept to a minimum.