Skip to content

docs: Fix and improve docstrings#150

Merged
llucax merged 12 commits into
frequenz-floss:v1.x.xfrom
llucax:fix-docstrings
Jun 30, 2026
Merged

docs: Fix and improve docstrings#150
llucax merged 12 commits into
frequenz-floss:v1.x.xfrom
llucax:fix-docstrings

Conversation

@llucax

@llucax llucax commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

🤖 This pull request is part of an automated effort to improve the docstring documentation of all our projects.

Main issues being resolved:

  • Grammar/typo errors: 'provide' → 'provides' in module docstring, 'A apparent' → 'An apparent', typo 'the a current' fixed in three files
  • Property docstring style: base_value and base_unit in _quantity.py used imperative style with a Returns: section; corrected to one-line noun-phrase style (convention for properties)
  • Copy-paste errors in operator docstrings: ApparentPower.__mul__ and ReactivePower.__mul__ were copied from Power.__mul__ and incorrectly mentioned an 'energy' return and 'duration' argument that don't apply; Energy.__mul__ omitted the float case; __truediv__ implementation docstrings in ApparentPower and ReactivePower referred to 'this power' throughout instead of the actual type
  • Misc _quantity.py issues: trailing blank line in from_string() Raises section; __truediv__ overload 1 incorrectly mentioned 'or percentage' in a float-only overload; arg descriptions in NoDefaultConstructible.__call__ started with lowercase
  • Absolute cross-references replaced with relative ones: __init__.py module docstring used fully-qualified [Name][frequenz.quantities.Name] forms; replaced with relative [Name][.Name] refs and backtick-styled display text
  • Multiple violations in experimental/marshmallow.py: missing 'A' prefix on class summaries, symbol mentions without cross-references throughout, _serialize/_deserialize missing Args:/Returns:/Raises: sections, unsupported Example usage: admonition renamed to Example:, missing inline docstring for TYPE_MAPPING class variable
  • Config: added relative_crossrefs: true to mkdocstrings options; added check-class-attributes, check-style-mismatch, and require-inline-class-var-docs to pydoclint config; added marshmallow objects.inv inventory for cross-reference resolution

@llucax llucax requested a review from a team as a code owner June 30, 2026 10:49
@llucax llucax requested review from shsms and removed request for a team June 30, 2026 10:49
@github-actions github-actions Bot added part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:code Affects the code in general labels Jun 30, 2026
@llucax llucax force-pushed the fix-docstrings branch 2 times, most recently from 9c91c57 to 10ee0df Compare June 30, 2026 11:14
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jun 30, 2026
@llucax llucax enabled auto-merge June 30, 2026 11:14
llucax added 11 commits June 30, 2026 13:17
Add the `relative_crossrefs: true` option to the mkdocstrings
Python handler options in mkdocs.yml. This enables relative cross-
reference resolution in docstrings, which is the current convention
being rolled out across all Frequenz Python projects.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Add missing pydoclint options to the [tool.flake8] configuration:

- check-class-attributes = true: enforce documentation of class
  attributes
- check-style-mismatch = true: detect when docstrings use a different
  style than what is configured
- require-inline-class-var-docs = true: require inline documentation
  for class variables

These are part of the convention being actively rolled out across all
Frequenz Python projects.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
- Fix subject-verb agreement in __init__.py module docstring:
  'provide' -> 'provides'
- Fix article agreement in ApparentPower class docstring:
  'A apparent power' -> 'An apparent power'
- Fix typo 'the a current' -> 'a current' in ApparentPower,
  Power and ReactivePower __truediv__ overload docstrings

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Properties must use a one-line noun phrase starting with 'The'
rather than imperative style with a Returns: section.

- base_value: 'Return the value...' + Returns section ->
  'The value of this quantity in the base unit.'
- base_unit: 'Return the base unit...' + Returns section ->
  'The base unit of this quantity, or None if this quantity has no unit.'

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Several operator docstrings were copied from Power and never
updated to refer to the correct quantity type:

- ApparentPower.__mul__: was 'power or energy' (wrong, no Energy
  return), now 'Scale this apparent power by a scalar or percentage'
- ApparentPower.__truediv__: 'this power' -> 'this apparent power'
  throughout all overloads and implementation
- Energy.__mul__: was 'percentage' only, now 'scalar or percentage'
  to match the float | Percentage signature
- Energy.__truediv__: implementation was 'power or duration' (omitted
  the Self and float cases), now 'scaled energy, ratio, power, or duration'
- ReactivePower.__mul__: was 'power or energy' (wrong), now
  'Scale this reactive power by a scalar or percentage'
- ReactivePower.__truediv__: 'this power' -> 'this reactive power'
  throughout all overloads and implementation

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
- Remove trailing blank line inside from_string() Raises: section
- Fix __truediv__ overload 1: arg description incorrectly mentioned
  'or percentage' in a float-only overload
- Capitalize arg descriptions in NoDefaultConstructible.__call__:
  'ignored positional arguments' -> 'Ignored positional arguments'

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
…_.py

Use name-based auto-resolve form [`Foo`][] and relative cross-
references like [.Power.from_watts] and [.experimental.marshmallow]
instead of absolute fully-qualified paths like
[frequenz.quantities.Power]. This is consistent with the convention
of using relative cross-references (relative_crossrefs: true) wherever
possible.

Also add backtick formatting to cross-reference display text for the
class list and the Quantity mention in the prose.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The experimental marshmallow module references marshmallow.ValidationError
in docstrings. Add the marshmallow readthedocs inventory so mkdocstrings
can resolve the cross-reference correctly.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
- Module docstring: absolute cross-ref -> [`QuantitySchema`][]
- serialize_as_string_default: fix summary ('The context variable...'),
  backtick True/False
- _QuantityField class: add 'A' prefix, add cross-refs for Quantity,
  field_type, QuantitySchema.TYPE_MAPPING, QUANTITY_FIELD_CLASSES;
  use relative references (.field_type, ..QuantitySchema.TYPE_MAPPING)
- field_type attribute: add Quantity cross-reference
- _serialize: add Args and Returns sections
- _deserialize: add Args, Returns, and Raises sections with
  marshmallow.ValidationError cross-reference
- Field subclasses (9): add 'A' prefix and quantity cross-refs
- QUANTITY_FIELD_CLASSES: fix summary ('The mapping from...'),
  add cross-ref to QuantitySchema.TYPE_MAPPING
- QuantitySchema: 'Example usage:' -> 'Example:'
- TYPE_MAPPING: add missing inline docstring

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
…aths

mkdocstrings resolves targets not starting with '.' as absolute paths,
and name-based lookup (empty []) is unreliable in module/attribute
docstring contexts. Fix all ambiguous references:

- __init__.py: use [.ClassName] (relative to module) for all type
  cross-refs in the module docstring instead of [`Foo`][]
- marshmallow.py module docstring: [.QuantitySchema] instead of []
- _QuantityField: use frequenz.quantities.Quantity absolute path for
  Quantity (external module); use [..QuantitySchema] (two dots = module
  level from class context) for QuantitySchema; use [..X] for all
  module-level symbols referenced from a class docstring
- QUANTITY_FIELD_CLASSES: use [..QuantitySchema.TYPE_MAPPING] (constant
  docstring context: one dot = constant itself, two dots = module)
- Field subclasses: use frequenz.quantities.X absolute paths for all
  quantity type cross-references (they live in a different module)

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
- Wrap overlong lines (E501) in class summary, _serialize and
  _deserialize summaries, and QUANTITY_FIELD_CLASSES docstring
- _serialize: add missing Raises section for TypeError (DOC501/DOC503)
- _deserialize: document both TypeError and ValidationError in Raises;
  use bare exception name 'ValidationError' for pydoclint compatibility
  (DOC503 cannot match cross-reference markup in exception names), with
  a link to marshmallow.ValidationError in the description
- QuantitySchema: remove blank line between Example: header and
  code fence (D412)
- _deserialize summary: rewrite as single line ending with period to
  fix D205 and D400

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
All cross-references to frequenz.quantities.* symbols were written as
absolute paths. Replace them with dot-notation relative references:

- Depth-1 objects (classes, module-level constants): use ....X (3 levels
  up from class/constant → frequenz.quantities.X)
- Depth-2 objects (methods, class attributes): use .....X (4 levels up)
- In _serialize/_deserialize method docstrings: [.field_type] was wrong
  (resolved to the method's own field_type, which doesn't exist); fixed
  to [..field_type] (1 level up → _QuantityField.field_type)

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax added this pull request to the merge queue Jun 30, 2026
Merged via the queue into frequenz-floss:v1.x.x with commit c8181db Jun 30, 2026
9 checks passed
@llucax llucax deleted the fix-docstrings branch June 30, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:code Affects the code in general part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants