From 869ccd68ae2fe0914f383b1fd8f949c264a14af0 Mon Sep 17 00:00:00 2001 From: Filip Poplewski Date: Wed, 26 Jun 2024 02:38:49 +0200 Subject: [PATCH 1/3] docs: add a more precise example Previous example used manual integer value assignment in class based declaration but in functional syntax has been used auto value assignment what could be confusing for the new users. Additionally documentation doesn't show how to declare new enum via functional syntax with usage of the manual value assignment. --- Doc/library/enum.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 8b3f397ea862f4..bfb7729918aa13 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -35,16 +35,17 @@ An enumeration: Enumerations are created either by using :keyword:`class` syntax, or by using function-call syntax:: - >>> from enum import Enum - - >>> # class syntax - >>> class Color(Enum): - ... RED = 1 - ... GREEN = 2 - ... BLUE = 3 - - >>> # functional syntax - >>> Color = Enum('Color', ['RED', 'GREEN', 'BLUE']) + from enum import Enum + + + class Color(Enum): + RED = '#FF0000' + GREEN = 65280 + BLUE = '#0000FF' + + + # functional syntax + Color = Enum('Color', [('RED', '#FF0000'), ('GREEN', 65280), ('BLUE', '#0000FF')]) Even though we can use :keyword:`class` syntax to create Enums, Enums are not normal Python classes. See From 74cbdcce21605e5c6f062201985454641645eeda Mon Sep 17 00:00:00 2001 From: "Filip \"Ret2Me\" Poplewski" <37419029+Ret2Me@users.noreply.github.com> Date: Wed, 26 Jun 2024 02:46:20 +0200 Subject: [PATCH 2/3] docs: remove whitespace characters --- Doc/library/enum.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index bfb7729918aa13..4ca9e8f35a2669 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -37,13 +37,13 @@ using function-call syntax:: from enum import Enum - + class Color(Enum): RED = '#FF0000' GREEN = 65280 BLUE = '#0000FF' - - + + # functional syntax Color = Enum('Color', [('RED', '#FF0000'), ('GREEN', 65280), ('BLUE', '#0000FF')]) From 7683e6e42e630bd57a5fcd19104a61aa54a2858a Mon Sep 17 00:00:00 2001 From: Filip Poplewski Date: Wed, 17 Jul 2024 00:02:07 +0200 Subject: [PATCH 3/3] refactor: change example --- Doc/library/enum.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 4ca9e8f35a2669..eb264fc37b02ef 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -35,17 +35,16 @@ An enumeration: Enumerations are created either by using :keyword:`class` syntax, or by using function-call syntax:: - from enum import Enum + >>> from enum import Enum + >>> # class syntax + >>> class Color(Enum): + ... RED = 1 + ... GREEN = 2 + ... BLUE = 3 - class Color(Enum): - RED = '#FF0000' - GREEN = 65280 - BLUE = '#0000FF' - - - # functional syntax - Color = Enum('Color', [('RED', '#FF0000'), ('GREEN', 65280), ('BLUE', '#0000FF')]) + >>> # functional syntax + >>> Color = Enum('Color', [('RED', 1), ('GREEN', 2), ('BLUE', 3)]) Even though we can use :keyword:`class` syntax to create Enums, Enums are not normal Python classes. See