FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Separate deprecation warnings from documentation notices by llucax · Pull Request #214 · frequenz-floss/frequenz-core-python · GitHub

Repository navigation

Separate deprecation warnings from documentation notices - #214

Merged
llucax merged 5 commits into
frequenz-floss:v1.x.xfrom
llucax:deprecation-notices-split
Oct 23, 2026
Merged

llucax merged 5 commits into
frequenz-floss:v1.x.xfrom
llucax:deprecation-notices-split

Conversation

llucax commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

The deprecations guide now separates the runtime warning (plain text, fully qualified names, no version) from the Deprecated: notice in the API documentation (version and a link to the replacement), and griffe-frequenz-core generates the notice from the helpers' structured arguments. This makes both helpers fit that split:

__getattr__ = deprecated_aliases(
    __name__,
    # Warns "mypkg.Decimal is deprecated. Use decimal.Decimal instead."
    DeprecatedAlias("Decimal", new_module="decimal", since="v1.2.0"),
    # A custom warning no longer loses the version for the documentation
    DeprecatedAlias(
        "Sensor",
        new_module="frequenz.client.common.microgrid.sensors",
        since="v0.6.0",
        message="{old} is deprecated. Use {new} instead, obtained from the client.",
    ),
)


class TaskStatus(Enum):
    OPEN = 1
    # Warns "mypkg.TaskStatus.PENDING is deprecated. Use mypkg.TaskStatus.OPEN instead."
    PENDING = deprecated_member(1, new_name="OPEN", since="v1.2.0")
  • DeprecatedAlias's standard warning drops the version, and since (documentation only) and message (warning only) become independent.
  • deprecated_member() gains keyword-only new_name and since, and generates a fully qualified warning when there is no message. The enum class checks that new_name is a non-deprecated member of the same enum.
  • The enum examples follow the guide. The old Enum example also asserted that TaskStatus["DONE"] was TaskStatus.FINISHED, which had a different value.

Everything is additive except the text of the standard alias warning and DeprecatedMember.message becoming str | None; DeprecatedMember is documented as not for direct use, so this goes into v1.6.0.

griffe-frequenz-core reads the new arguments in frequenz-floss/griffe-frequenz-core#10. Its compat tests assert the version in the alias warning, so they need updating when it bumps its exact core pin.

Fixes #206.

Every deprecation has two texts for two different readers: the runtime
warning, read in a terminal far from the deprecated symbol, and the
`Deprecated:` notice in the API documentation, read right where it is
documented. The deprecations guide (frequenz-floss/docs#6) now gives
them different rules: the warning is plain text without the version,
and the notice says since which version the symbol is deprecated and
links its replacement.

`DeprecatedAlias` mixed the two: `since` went into the warning, and
`since` and `message` excluded each other, so an alias with a custom
warning had no version left for `griffe-frequenz-core` to put in its
notice.

Now the standard warning is `<old> is deprecated. Use <new> instead.`,
`since` is only documentation metadata, and `message` only replaces the
warning, so an alias can give both, either or neither. At least one of
`new_module` and `new_name` is still required, which is all the
overloads have to check now, so the four collapse into two.

Only the text of the standard warning changes, and the check that is
dropped only refused calls that are now valid, so nothing that worked
before breaks.

The docs now say what `since` and `message` are for, and that a
hand-written `Deprecated:` admonition on the alias declared for type
checkers is how the notice is changed.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
A deprecated enum member only had its runtime message, so every one
needed a hand-written `Deprecated:` notice repeating the same
information, even for a plain rename. Client libraries can potentially
deprecate (rename) dozens of members in a release.

`deprecated_member()` and `DeprecatedMember` now take the same
structured information as `DeprecatedAlias`: a keyword-only `new_name`,
the member to use instead in the same enum, and `since`, the version it
is deprecated since, which is only documentation metadata for
`griffe-frequenz-core`. `message` gets a `None` default, and at least
one of `message` and `new_name` is required, which overloads let mypy
check.

    PENDING = deprecated_member(1, new_name="OPEN", since="v1.2.0")

Without `message`, the warning is generated as `<Enum>.<NAME> is
deprecated. Use <Enum>.<new_name> instead.`, with fully qualified names,
as the deprecations guide asks. It can only be built when the enum class
is created, since only then are its module and qualified name known, so
the metaclass generates it then. It also checks that `new_name` is a
member of the same enum and is not deprecated itself, so a typo or a
chain of deprecations fails at import time instead of pointing users at
something that doesn't work.

`message` stays a literal message rather than an `{old}`/`{new}`
template like `DeprecatedAlias`'s, since existing messages may contain
braces, and it is still not checked, as before.

Existing calls keep working, since `value` and `message` keep their
position and names and the new parameters are keyword-only. The only
visible change is that `DeprecatedMember.message` is now `str | None`,
as a generated message is not known when the member is declared. The
class is documented as not meant to be used directly, so this is
acceptable in a minor release; storing the generated message back into
it would have kept the type but left it without a meaningful value
until the class is created.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The `Enum`, `unique()` and README examples still wrote messages like
`PENDING is deprecated, use OPEN instead`, which the deprecations guide
no longer recommends: a warning has to start with the fully qualified
name, which the own-deprecations `pytest` filter relies on, and the
version belongs in the documentation notice.

They now use the structured `deprecated_member()` form for renames, and
the `Enum` example also shows a member with no replacement, which gives
its own fully qualified `message` and needs a hand-written notice. The
text after it says what each one warns and how it is documented.

The `Enum` example also claimed that `TaskStatus["DONE"]` and
`TaskStatus(3)` were `TaskStatus.FINISHED`, which had a different value,
and went unnoticed because the examples are only linted, not run. The
new example asserts what actually happens.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
llucax requested a review from a team as a code owner October 23, 2026 12:52
llucax requested review from shsms and removed request for a team October 23, 2026 12:52
llucax added this to the v1.6.0 milestone Oct 23, 2026
github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:enum Affects the enum module labels Oct 23, 2026
llucax requested a review from Marenz October 23, 2026 12:56
llucax self-assigned this Oct 23, 2026
llucax removed this from the v1.6.0 milestone Oct 23, 2026
llucax added the part:warnings Affects the `warnings` module label Oct 23, 2026
The `frequenz.core.warnings` module was added in v1.5.0 and the
`part:warnings` label already exists in the repository, but neither
the labeler, the key labeler nor the bug report template knew about
it, so pull requests and issues touching the module were not labeled.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
github-actions Bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Oct 23, 2026
llucax enabled auto-merge October 23, 2026 13:17

Marenz 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

🤖 LGTM. The warning and the documentation metadata are now cleanly separated, and the upgrading notes cover the changed warning text.

llucax added this pull request to the merge queue Oct 23, 2026
Merged via the queue into frequenz-floss:v1.x.x with commit 36190e1 Oct 23, 2026
9 checks passed
llucax deleted the deprecation-notices-split branch October 23, 2026 14:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:enum Affects the enum module part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:warnings Affects the `warnings` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate deprecation warnings from documentation notices in the deprecation helpers

2 participants


Back | FazBrowse Home | New Git URL