From 4889de5695a1b48c6e98fe854e2b5cf0ac5fd0e8 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 26 Oct 2026 10:56:53 +0000 Subject: [PATCH] Show the hand-written notice in the Enum example The `Enum` example's text says `CANCELLED` gives its own `message`, so its notice is written by hand as a `Deprecated:` admonition in the member's docstring, but the example itself had no docstring, so copying it gave a member that `griffe-frequenz-core` documents with its runtime warning, with a warning that fails a strict documentation build. It now shows that docstring, as the deprecations guide's own example does. `CANCELLED` also drops `since`: with a `message` and no `new_name` there is no generated notice for it to go into, and the hand-written one already says the version. The class docstring now uses single quotes, so the example can hold a triple-quoted docstring, as `frequenz.core.id`'s module docstring does. Signed-off-by: Leandro Lucarella --- src/frequenz/core/enum.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/frequenz/core/enum.py b/src/frequenz/core/enum.py index d683662..5cc21d0 100644 --- a/src/frequenz/core/enum.py +++ b/src/frequenz/core/enum.py @@ -385,7 +385,7 @@ class Enum(enum.Enum): # noqa else: class Enum(enum.Enum, metaclass=DeprecatingEnumType): - """Base class for enums that support deprecated members. + '''Base class for enums that support deprecated members. This class extends the standard library's [`enum.Enum`][] to support marking certain members as deprecated. Deprecated members can be accessed, but doing so @@ -412,8 +412,12 @@ class TaskStatus(Enum): 4, "mypkg.TaskStatus.CANCELLED is deprecated. " "Cancelled tasks are deleted now.", - since="v1.3.0", ) + """The task was cancelled. + + Deprecated: + Deprecated since v1.3.0. Cancelled tasks are deleted now. + """ # Accessing deprecated members by name warns: status1 = TaskStatus.PENDING @@ -442,8 +446,9 @@ class TaskStatus(Enum): `CANCELLED` has no member to point at, so it gives its own `message`, starting with its fully qualified name. That replaces the warning only, so its notice is written by hand, as a `Deprecated:` admonition - in the member's docstring. - """ + in the member's docstring. That notice says the version too, so + `since` is not needed. + ''' __deprecated_names__: ClassVar[Mapping[str, str]] __deprecated_value_map__: ClassVar[Mapping[Self, str]]