- Use
uvfor dependency management - Virtual environment must be in
.venvdirectory - Always run
uv syncbefore executing code
- All functions must have complete type annotations (parameters and return types)
- Use
from __future__ import annotationsat the top of every file - Prefer
list[str]overList[str](modern syntax) - Use
X | Noneinstead ofOptional[X] - No
Anytypes unless absolutely necessary (and document why)
- Use
beartypedecorator on all public functions - Import pattern:
from beartype import beartype
@beartype
def my_function(name: str, count: int) -> list[str]:
...When creating a new project:
uv init
uv add beartype
uv add --dev mypy pyrightAlways run through uv:
uv run python script.py
uv run mypy .
uv run pyrightInclude these settings:
[tool.mypy]
strict = true
python_version = "3.12"
[tool.pyright]
typeCheckingMode = "strict"
pythonVersion = "3.12"Every Python file should start with:
from __future__ import annotations
from beartype import beartype