Skip to content

Style deprecation notices in the API reference - #288

Draft
llucax wants to merge 4 commits into
frequenz-floss:v0.x.xfrom
llucax:deprecated-admonitions
Draft

llucax wants to merge 4 commits into
frequenz-floss:v0.x.xfrom
llucax:deprecated-admonitions

Conversation

@llucax

@llucax llucax commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Preparation for the client-common 0.4.1 update, so deprecation notices already look right by the time it adds more of them.

First, the styling: a CSS rule for the deprecated admonition class (gravestone icon, its own colour, otherwise like a warning), and the griffe-warnings-deprecated extension wired into the mkdocstrings handler so symbols decorated with typing_extensions.deprecated get an admonition generated for them. The extension's kind is set to deprecated rather than the default warning, so what it emits is markup-identical to a hand-written Deprecated: admonition, and one rule styles both.

Then a third commit brings every deprecation in the repo in line with the deprecations guide, because most of them were not reaching the rendered documentation at all.

The nine Warning: Deprecated blocks on symbols the decorator already marks are removed rather than converted, since the extension generates one for those and a hand-written copy would show the notice twice.

Two things worth a reviewer's eye:

  • ElectricalComponentCategory now spells its decorator message out as a literal instead of reusing the module constant. griffe renders the admonition only when it can read the message statically, so built from a module-level name it produced nothing.
  • docs/wrapping-guide/deprecation-and-compatibility.md was updated to describe the new deprecation style..

Style the `deprecated` admonition class like a warning, but with the
`material/grave-stone` icon and its own colour, so deprecation notices
read as deprecation notices and not as generic warnings.

That class is what a hand-written `Deprecated:` admonition in
a docstring produces, and also what the griffe extension added next
will emit, so a single rule covers both sources.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Wire the `griffe-warnings-deprecated` extension into the mkdocstrings
handler options, so every symbol decorated with
`typing_extensions.deprecated` gets a "Deprecated" admonition in the
API reference with no docstring edit at all.

The extension's `kind` is set to `deprecated` rather than the default
`warning`, so it emits `class="deprecated"`, which is exactly what
a hand-written `Deprecated:` admonition produces. The CSS rule added
in the previous commit then styles both, and the two are visually
indistinguishable. That matters because the decorator cannot reach
everything: module-level aliases, a single function argument, enum
members and whole modules still need the admonition written by hand.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax
llucax requested a review from a team as a code owner September 21, 2026 12:47
@llucax
llucax requested review from Marenz and removed request for a team September 21, 2026 12:47
@llucax

llucax commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Example of how it looks.

image

@llucax llucax self-assigned this Sep 21, 2026
@llucax
llucax enabled auto-merge September 21, 2026 12:48
@github-actions github-actions Bot added part:docs Affects the documentation part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels Sep 21, 2026
@llucax
llucax disabled auto-merge September 21, 2026 12:54
@github-actions github-actions Bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:grid Affects the grid protobuf definitions part:metrics Affects the metrics protobuf definitions part:microgrid Affects the microgrid protobuf definitions part:pagination Affects the pagination protobuf definitions labels Sep 21, 2026
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Sep 21, 2026
@llucax

llucax commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Updated: pushed 3013200 and rewrote the description.

The PR originally only added the styling and deliberately left existing notices alone, which meant it landed a styling rule that almost nothing in this repo used. It now also brings every deprecation in line with the deprecations guide, which turned out to be most of them:

  • The 26 enum members using frequenz.core.enum.deprecated_member said nothing at all in the docs. The helper predates PEP 702, so griffe generates no admonition for it. They now have hand-written ones, matching what client-microgrid already does.
  • MetricSample.sample_time and .bounds carry the decorator, but griffe does not see it underneath @property, so they generated nothing either.
  • The delivery-area code field and invalid DeliveryArea construction used Warning: admonitions, which render as ordinary warnings.
  • The nine Warning: Deprecated blocks on symbols the decorator does mark are removed, since the extension now generates those and a hand-written copy would show the notice twice. Their extra explanation stays as prose in the docstring body.
  • The decorator messages are rewritten to the guide's form: fully qualified plain names, the replacement as a bare [name][] cross-reference, and "since v0.4.1" in the sentence.

That takes the rendered count from 0 to 43.

Two things I would like a second opinion on:

  1. ElectricalComponentCategory now spells its decorator message out as a literal instead of reusing the module constant. griffe renders the admonition only when it can read the message statically, so built from a module-level name it produced nothing. The duplication is the price of the notice appearing at all.
  2. docs/wrapping-guide/deprecation-and-compatibility.md was updated to describe the new style.

Two tests asserted a full message and were updated; the rest match a substring. nox is green (2052 tests, mypy, pylint, flake8/pydoclint, black, isort) and the strict docs build passes.

cmd:skip-release-notes is applied: docstrings and warning text change, the API does not.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Decorated properties currently render duplicate notices, and several messages and tests do not follow the newly documented exact format.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 4 Medium severity · 1 Low severity

Open (5)
What changed in this PR

Adds consistent deprecation notices to generated API documentation.

Changes:

  • Adds and styles generated Deprecated admonitions.
  • Standardizes deprecation messages and documentation.
  • Updates warning-message tests.
File Description
pyproject.toml Adds the Griffe deprecation extension.
mkdocs.yml Configures generated deprecation admonitions.
docs/​_css/​mkdocstrings.css Styles deprecated notices.
docs/​wrapping-guide/​deprecation-and-compatibility.md Documents the new convention.
src/​frequenz/​client/​common/​streaming/​_event.py Documents enum-member deprecation.
src/​frequenz/​client/​common/​proto/​_datetime.py Updates converter deprecation.
src/​frequenz/​client/​common/​pagination/​proto/​v1alpha8/​_pagination_info.py Updates converter deprecation.
src/​frequenz/​client/​common/​microgrid/​electrical_components/​proto/​v1alpha8/​_category.py Updates legacy converter notices.
src/​frequenz/​client/​common/​microgrid/​electrical_components/​_state_code.py Documents enum-member deprecation.
src/​frequenz/​client/​common/​microgrid/​electrical_components/​_diagnostic_code.py Documents enum-member deprecation.
src/​frequenz/​client/​common/​microgrid/​electrical_components/​_category.py Documents category and member deprecations.
src/​frequenz/​client/​common/​microgrid/​components/​__init__.py Updates ComponentId deprecation.
src/​frequenz/​client/​common/​metrics/​proto/​v1alpha8/​_sample.py Updates legacy converter notices.
src/​frequenz/​client/​common/​metrics/​proto/​v1alpha8/​_bounds.py Updates bounds converter notices.
src/​frequenz/​client/​common/​metrics/​_sample.py Updates property and enum deprecations.
src/​frequenz/​client/​common/​metrics/​_metric.py Documents enum-member deprecation.
src/​frequenz/​client/​common/​grid/​proto/​v1alpha8/​_delivery_area.py Updates converter deprecation.
src/​frequenz/​client/​common/​grid/​_delivery_area.py Documents delivery-area deprecations.
tests/​proto/​test_datetime.py Updates exact warning assertion.
tests/​pagination/​proto/​v1alpha8/​test_pagination_info.py Updates exact warning assertion.
tests/​metrics/​test_sample_metric_sample.py Updates property warning assertion.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/frequenz/client/common/metrics/_sample.py Outdated
Comment thread src/frequenz/client/common/metrics/proto/v1alpha8/_bounds.py Outdated
Comment thread src/frequenz/client/common/metrics/proto/v1alpha8/_sample.py Outdated
Comment thread tests/metrics/test_sample_metric_sample.py
Comment thread docs/wrapping-guide/deprecation-and-compatibility.md Outdated

@daniel-zullo-frequenz daniel-zullo-frequenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, there are a few comments from Copilot but I think most of them can be ignored. I'll approve it again once you've assessed/resolved the existing comments

@llucax
llucax force-pushed the deprecated-admonitions branch from 8ef0237 to 9e5cd51 Compare September 22, 2026 13:47
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The previous commit changed every deprecation notice in the repo but left
the wrapping guide describing the old message form, `"<old FQCN> is
deprecated. Use <new FQCN> instead."`, with no version and no
cross-reference brackets. The guide is what a contributor reads before
writing a new deprecation, so leaving it behind would reintroduce the old
form.

It now describes the form the code uses and why: the version in the
sentence because a separate "since" line cannot be expressed through the
decorator, the replacement as a bare `[name][]` cross-reference so the
generated admonition links to it, no backticks because the same string is
printed as a runtime warning, and implicit concatenation of single-line
strings because a triple-quoted message carries its indentation into both
the cross-reference and the terminal.

The worked example is updated to match, and now escapes the brackets and
dots in its `pytest.deprecated_call()` regex. That is easy to get wrong
silently, because `match` is a search and an unescaped `[...]` is a
character class that still matches something.

Also added is the hand-written `Deprecated:` admonition for the cases the
decorator cannot reach, which the guide never mentioned: an argument, an
enum member, or construction being made stricter, all of which the repo
now has. The `deprecated_member` paragraph says outright that the helper
produces no admonition on its own, since that is the whole reason the
members need one written by hand.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax
llucax force-pushed the deprecated-admonitions branch from 9e5cd51 to 441e8ef Compare September 22, 2026 13:53
@llucax

llucax commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Updated, but I'm exploring an mkdocs extension so some of the fixes here are not necessary (like the duplicated deprecated_member() in enums requiring a duplicate Deprecated: admonition for the docs.

@llucax
llucax disabled auto-merge September 22, 2026 13:54
@llucax
llucax marked this pull request as draft September 22, 2026 13:55

This branch has not been deployed

No deployments
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:docs Affects the documentation part:grid Affects the grid protobuf definitions part:metrics Affects the metrics protobuf definitions part:microgrid Affects the microgrid protobuf definitions part:pagination Affects the pagination protobuf definitions part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants