Skip to content

module-attribute-type-mismatch (PDF719)

Added in 1.0.0 Never fix Convention

Part of the PDF rule category.

View source · View documentation source · Search issues

Fix is not available.

Rule is disabled if docstring-convention is none or pep257.

Rule is incompatible with PDF718.

What it does

Checks that parsed module attribute docstring types conservatively match annotated module attributes.

The comparison uses a small, syntax-only type-expression subset. Unparseable or ambiguous expressions are skipped instead of guessed. Only entries that match inventoried module attributes are checked, and NumPy entries that document multiple names are checked once per matching attribute.

Why is this useful?

Stale module attribute type text can mislead readers when annotations have changed.

Ruff compatibility

None.

Examples

PDF719 reports module attribute docstring types that do not match annotations:

docstring-convention = "google"
"""Module.

Attributes:
    timeout (str): Timeout in seconds.
"""

timeout: int = 1
PDF719: Line 4: Module attribute 'timeout' docstring type does not match the annotation

Matching module attribute types are accepted:

docstring-convention = "google"
"""Module.

Attributes:
    timeout (int): Timeout in seconds.
"""

timeout: int = 1

NumPy entries that document multiple names are checked once per matching attribute:

docstring-convention = "numpy"
"""Module.

Attributes
----------
primary, fallback : str
    Request endpoints.
"""

primary: str
fallback: int
PDF719: Line 5: Module attribute 'fallback' docstring type does not match the annotation

Options

None.