Commit Graph

162 Commits

Author SHA1 Message Date
Ethan Furman e79c39101a gh-118342: [Enum] update docs (GH-137290)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-12-18 18:31:37 +00:00
Peter f3d7faeafa gh-139487: add missing imports for standalone doctest Enum examples (#139488) 2025-10-02 12:28:29 +02:00
RafaelWO 003bd8cc63 gh-136672: Docs: Move Enum functions and add examples (GH-136791)
* Docs: Move Enum functions and add examples

When the `Enum` functions `_add_alias_` and `_add_value_alias_` were added in de6bca9564, the documentation for them was done under `EnumType` instead of `Enum`.

This change moves them to the docs of the `Enum` class and adds an example for each function.

---------

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2025-08-12 12:28:27 -07:00
Nacho Caballero 5f9e38f9b9 gh-136859: Improve StrEnum docs (GH-136864)
Co-authored-by: Nacho Caballero <nacho.caballero@astrazeneca.com>
Co-authored-by: Antonio Spadaro <ilovelinux@users.noreply.github.com>
2025-07-21 08:18:40 -07:00
Victorien d05053a203 Fix typo in enum documentation (#129920) 2025-02-09 21:48:11 +00:00
Petr Viktorin 2a66dd33df gh-112328: Make EnumDict usable on its own and document it (GH-123669)
Co-authored-by: Rafi <rafi.promit@gmail.com>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2024-12-20 11:40:58 -08:00
Md Rokibul Islam 39e69a7cd5 gh-112328: Document EnumDict in docs and release notes (GH-121720)
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2024-12-19 15:38:42 -08:00
Filip "Ret2Me" Poplewski ff257c7843 docs: add a more precise example in enum doc (GH-121015)
* 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.

* docs: remove whitespace characters

* refactor: change example

---------

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2024-11-01 12:28:50 -07:00
Wei-Hsiang (Matt) Wang 103a0470e3 gh-123492: Remove unnecessary :func: parentheses (#123493) 2024-08-30 14:34:09 +03:00
Damien 8e2dc7f380 gh-123005: Add version added in enum.Flag.__len__ (GH-123007) 2024-08-14 13:30:33 -07:00
Saul Pwanson 0506f75c53 fix enum doc typo (#120091) 2024-06-17 21:31:15 +05:30
Nikita Sobolev 7fadfd82eb gh-120361: Add nonmember test with enum flags inside to test_enum (GH-120364)
* gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
2024-06-14 10:25:35 -07:00
Ned Batchelder bcb435ee8f docs: module page titles should not start with a link to themselves (#117099) 2024-05-08 20:34:40 +01:00
chrysn f58833ebf8 gh-118650: Document Enum._repr_* reservation exclusion (GH-118698) 2024-05-07 11:11:18 -07:00
Momo Eissenhauer 48e52fe2c9 gh-118310: Fix documentation for enum.Enum.__new__ (GH-118311)
The provided example was incorrect:
- The example enum was missing the `int` mixin as implied by the context
- The value of `int('1a', 16)` was incorrectly given as 17
  (should be 26)
2024-05-07 13:42:18 +02:00
Philipp A 5a4d3df2fa Fix note in Enum.__new__ docs (#118284) 2024-04-26 07:06:53 -07:00
Nicolas A. Oyarzabal 601f3a7b33 gh-105535 Document potential performance trap during enum creation (GH-107119)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-03-08 11:22:17 -08:00
HarryLHW 4859ecb860 gh-116281: Remove wrong '\' from '\*' in some doc signatures (#116282) 2024-03-03 14:32:32 -05:00
Ethan Furman 3ea78fd5bc gh-115821: [Enum] better error message for calling super().__new__() (GH-116063)
docs now state to not call super().__new__
if super().__new__ is called, a better error message is now used
2024-02-28 15:17:49 -08:00
Nikita Sobolev 553c90ccc2 gh-101100: Fix sphinx warnings in library/enum.rst (#114696)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2024-02-08 23:40:28 -07:00
Finite State Machine 3f71c416c0 gh-115106 docs: 'enum.Flag.__iter__()' did not exist prior to Python 3.11 (GH-115107)
change versionchanged to versionadded
2024-02-06 17:28:01 -08:00
Ethan Furman ff7588b729 gh-114071: [Enum] update docs and code for tuples/subclasses (GH-114871)
Update documentation with `__new__` and `__init__` entries.

Support use of `auto()` in tuple subclasses on member assignment lines.  Previously, auto() was only supported on the member definition line either solo or as part of a tuple:

    RED = auto()
    BLUE = auto(), 'azul'

However, since Python itself supports using tuple subclasses where tuples are expected, e.g.:

    from collections import namedtuple
    T = namedtuple('T', 'first second third')

    def test(one, two, three):
        print(one, two, three)

    test(*T(4, 5, 6))
    # 4 5 6

it made sense to also support tuple subclasses in enum definitions.
2024-02-04 07:22:55 -08:00
Miyashita Yosuke ba683c22ec gh-114231: Fix indentation in enum.rst (#114232) 2024-01-18 09:23:15 +00:00
Ethan Furman de6bca9564 gh-112328: [Enum] Make some private attributes public. (GH-112514)
* [Enum] Make some private attributes public.

- ``_EnumDict`` --> ``EnumDict``
- ``EnumDict._member_names`` --> ``EnumDict.member_names``
- ``Enum._add_alias_``
- ``Enum._add_value_alias_``

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-12-05 08:27:36 -08:00
Khalil Mouawad 14f52e1548 gh-110679: Improved markup in enum.rst (GH-110747) 2023-10-25 10:32:09 -07:00
InSync c0ea67dd0d GH-111182: Update EnumType.__contains__ docs (GH-111184) 2023-10-24 10:30:13 -07:00
InSync 2c472a87c7 Remove unnecessary escape in Doc/library/enum.rst (GH-110780) 2023-10-12 15:04:36 -07:00
Ezio Melotti bb7923f556 gh-110631: Fix reST indentation in Doc/library (#110685)
Fix wrong indentation in the Doc/library dir.
2023-10-11 22:24:12 +02:00
Nikita Sobolev e8ef0bdd8c gh-107700: [Enum] Document that EnumType was added in 3.11 (GH-108260) 2023-08-22 07:34:18 -07:00
Thomas Hisch 3ac856e697 gh-104659: Consolidate python examples in enum documentation (#104665) 2023-05-19 11:46:20 -06:00
Ethan Furman 700ec657c8 gh-103596: [Enum] do not shadow mixed-in methods/attributes (GH-103600)
For example:

    class Book(StrEnum):
        title = auto()
        author = auto()
        desc = auto()

    Book.author.desc is Book.desc

but

    Book.author.title() == 'Author'

is commonly expected.  Using upper-case member names avoids this confusion and possible performance impacts.

Co-authored-by: samypr100 <3933065+samypr100@users.noreply.github.com>
2023-04-18 16:19:23 -07:00
Ethan Furman 2194071540 gh-103365: [Enum] STRICT boundary corrections (GH-103494)
STRICT boundary:

- fix bitwise operations
- make default for Flag
2023-04-13 08:24:33 -07:00
Ethan Furman 5ffc1e5a21 gh-98298, gh-74730: [Enum] update docs (GH-103163)
fix FlagBoundary statements
add warning about reloading modules and enum identity
2023-04-03 14:57:42 -07:00
Owain Davies 7f1c721756 gh-101739: [Enum] update docs - default boundary for Flag is CONFORM (GH-101746) 2023-02-17 13:36:47 -08:00
Peter Gessler 24cbc7a2a0 docs: Fix enum reassign str documentation (GH-101507) 2023-02-02 12:12:57 -08:00
Nikita Sobolev 9e025d305f gh-101100: [Enum] Fix sphinx warnings in docs (GH-101122)
* gh-101100: [Enum] Fix sphinx warnings in 

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2023-01-19 18:16:21 -08:00
Viicos c5660ae96f Fix typo in ReprEnum documentation (#101079) 2023-01-17 16:21:56 +05:30
Noam Cohen 2161bbf243 Fix typo in enum module documentation (#100992) 2023-01-12 21:10:29 +05:30
Christophe Nanteuil 64ed609c53 [Enum] docs: replace 'last value' by 'highest value' for Flag auto (GH-100709) 2023-01-03 14:08:50 -08:00
Beweeted 868bab0fdc gh-100174: [Enum] Correct PowersOfThree example. (GH-100178)
Changed from multiples of 3 to powers of 3 to match the class name.
2022-12-11 15:20:59 -08:00
Stanley 286e3c76a9 gh-99087: Add missing newline for prompts in docs (GH-98993)
Add newline for prompts so copying to REPL does not cause errors.
2022-12-08 19:31:19 -08:00
Ethan Furman 679efbb080 gh-94943: [Enum] improve repr() when inheriting from a dataclass (GH-99740)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-12-06 13:43:41 -08:00
Ethan Furman e3a3863cb9 gh-93464: [Enum] Add versionchanged tag (#99997)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-12-05 12:35:31 +02:00
Géry Ogam 2ae894b6d1 [Enum] Fix typos in the documentation (GH-99960) 2022-12-04 11:49:31 -08:00
Ethan Furman 73a921b070 gh-99304: [Enum] clarify what constitutes a flag alias (GH-99395)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-11-12 10:39:47 -08:00
Ethan Furman 8feb7ab77c gh-93464: [Enum] fix auto() failure during multiple assignment (GH-99148)
* fix auto() failure during multiple assignment

i.e. `ONE = auto(), 'text'` will now have `ONE' with the value of `(1,
'text')`.  Before it would have been `(<an auto instance>, 'text')`
2022-11-05 18:01:08 -07:00
Clément Robert 327fc1c6fa [Enum docs]: fix order of arguments to isinstance() (#98542) 2022-10-22 12:29:00 +01:00
Ethan Furman 3e95ffc7ae gh-98298: [Enum] document ReprEnum, global_enum, and show_flag_values (GH-98455)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-10-21 15:36:41 -07:00
180909 d6062d1170 GH-95172 Make the same version versionadded oneline (#95172)
* Make the same version versionadded oneline

* Format versionadded for enum.rst

* Format versionadded

A single line versionadded was reading better.

Co-authored-by: Senthil Kumaran <senthil@python.org>
2022-10-05 10:52:59 -07:00
Ethan Furman 4e704d7847 gh-95077: [Enum] add code-based deprecation warnings for member.member access (GH-95083)
* issue deprecation warning for member.member access
* always store member property in current class
* remove __getattr__
2022-07-25 11:05:10 -07:00