Guidelines for Writing Source Code¶
Type Annotations¶
Every function, variable, and class attribute must be strictly typed. No exceptions.
Use modern Python 3.12+ syntax:
- Type aliases with
typestatement - PEP 695 type parameters (
[T],[**P]) - Pipe unions (
str | int, notUnion[str, int]) - Proper optional types (
str | None, notOptional[str])
Linting and Type Checking¶
Always run just check and just format before committing. just check must show zero errors:
If there's absolutely no alternative, use # pyright: ignore[errorCode] or #NOQA: errorCode to ignore typing or linting errors.
Docstrings¶
Use Google-style docstrings. Include a "Why" section and "Example" section when it adds value:
def resolve_relative_path(
path: pathlib.Path, info: pydantic.ValidationInfo, must_exist: bool = True
) -> pathlib.Path:
"""Convert relative path to absolute path based on input file location.
Why:
Users reference files like `photo: profile.jpg` relative to their CV
YAML. This validator resolves such paths to absolute form and validates
existence, enabling file access during rendering.
Args:
path: Path to resolve (may be relative or absolute).
info: Validation context containing input file path.
must_exist: Whether to raise error if path doesn't exist.
Returns:
Absolute path.
"""
Docstring order:
- Brief description (one line)
- Why section (when it adds value)
- Example section (when it adds value)
- Args section (mandatory)
- Returns section (mandatory)
- Raises section (mandatory if function raises exceptions)