summaryrefslogtreecommitdiffstats
path: root/Doc/library/enum.rst
Commit message (Collapse)AuthorAgeFilesLines
* [Enum] docs: replace 'last value' by 'highest value' for Flag auto (GH-100709)Christophe Nanteuil2023-01-031-3/+3
|
* gh-100174: [Enum] Correct PowersOfThree example. (GH-100178)Beweeted2022-12-111-2/+2
| | | Changed from multiples of 3 to powers of 3 to match the class name.
* gh-99087: Add missing newline for prompts in docs (GH-98993)Stanley2022-12-091-0/+13
| | | Add newline for prompts so copying to REPL does not cause errors.
* gh-94943: [Enum] improve repr() when inheriting from a dataclass (GH-99740)Ethan Furman2022-12-061-0/+2
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* gh-93464: [Enum] Add versionchanged tag (#99997)Ethan Furman2022-12-051-0/+5
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* [Enum] Fix typos in the documentation (GH-99960)Géry Ogam2022-12-041-26/+26
|
* gh-99304: [Enum] clarify what constitutes a flag alias (GH-99395)Ethan Furman2022-11-121-12/+27
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* gh-93464: [Enum] fix auto() failure during multiple assignment (GH-99148)Ethan Furman2022-11-061-3/+12
| | | | | | * 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')`
* [Enum docs]: fix order of arguments to isinstance() (#98542)Clément Robert2022-10-221-1/+1
|
* gh-98298: [Enum] document ReprEnum, global_enum, and show_flag_values (GH-98455)Ethan Furman2022-10-211-1/+47
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* GH-95172 Make the same version `versionadded` oneline (#95172)1809092022-10-051-2/+1
| | | | | | | | | | | * 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>
* gh-95077: [Enum] add code-based deprecation warnings for member.member ↵Ethan Furman2022-07-251-7/+0
| | | | | | | access (GH-95083) * issue deprecation warning for member.member access * always store member property in current class * remove __getattr__
* gh-91456: [Enum] Deprecate default auto() behavior with mixed value types ↵Oscar R2022-06-231-0/+4
| | | | | | | (GH-91457) When used with plain Enum, auto() returns the last numeric value assigned, skipping any incompatible member values (such as strings); starting in 3.13 the default auto() for plain Enums will require all the values to be of compatible types, and will return a new value that is 1 higher than any existing value. Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* Restore default role check in `make check`. (#92290)Ezio Melotti2022-05-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | * Restore default role check in `make check`. * Options first, then files. * Update `make.bat` too. * Add a comment explaining the extra options. * No reason to ignore the README.rst. * Enable default-role check in sphinx-lint. Co-authored-by: Julien Palard <julien@palard.fr> * Update sphinx-lint default-role check. * Fix use of the default role in the docs. * Update make.bat to check for the default role too. * Fix comment in make.bat. Co-authored-by: Julien Palard <julien@palard.fr>
* Enum docs: Remove unnecessary apostrophes (#92382)Alex Waygood2022-05-061-2/+2
| | | Replace "it's" with "its".
* gh-78157: [Enum] nested classes will not be members in 3.13 (GH-92366)Ethan Furman2022-05-061-0/+21
| | | | | | | - add member() and nonmember() functions - add deprecation warning for internal classes in enums not becoming members in 3.13 Co-authored-by: edwardcwang
* bpo-46586: Fix documentation links (GH-31216)Meer Suri2022-02-121-1/+1
| | | * Fix enum.property documentation link
* bpo-46569: [Enum] fix typo in `StrEnum` docs (GH-31007)Nikita Sobolev2022-02-031-1/+1
|
* bpo-40066: [Enum] skip failing doc test (GH-30637)Kumar Aditya2022-01-171-92/+173
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-171-173/+92
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-161-92/+173
| | | | | | | | | | | | | | | Undo rejected PEP-663 changes: - restore `repr()` to its 3.10 status - restore `str()` to its 3.10 status New changes: - `IntEnum` and `IntFlag` now leave `__str__` as the original `int.__str__` so that str() and format() return the same result - zero-valued flags without a name have a slightly changed repr(), e.g. `repr(Color(0)) == '<Color: 0>'` - update `dir()` for mixed-in types to return all the methods and attributes of the mixed-in type - added `_numeric_repr_` to `Flag` to control display of unnamed values - enums without doc strings have a more comprehensive doc string added - `ReprEnum` added -- inheriting from this makes it so only `__repr__` is replaced, not `__str__` nor `__format__`; `IntEnum`, `IntFlag`, and `StrEnum` all inherit from `ReprEnum`
* bpo-46157: fix typo in docs (GH-30237)Kumar Aditya2021-12-231-1/+1
|
* bpo-45535: Improve output of Enum ``dir()`` (GH-29316)Alex Waygood2021-12-021-2/+3
| | | | | | Modify the ``EnumType.__dir__()`` and ``Enum.__dir__()`` to ensure that user-defined methods and methods inherited from mixin classes always show up in the output of `help()`. This change also makes it easier for IDEs to provide auto-completion.
* bpo-45740: [Enum] add versionadded markers to docs (GH-29443)Ethan Furman2021-11-061-0/+1
| | | [Enum] add versionadded markers to docs
* [doc] Fix typos found using codespell (GH-28744)Christian Clauss2021-10-051-2/+2
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44559: [Enum] correct `versionadded` to 3.11 for new features (GH-27388)Steffen Zeile2021-07-271-6/+6
|
* Fix typos in `Weekday.today` example (GH-27363)Steffen Zeile2021-07-261-1/+1
|
* bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752)Ethan Furman2021-06-181-4/+29
| | | | | | | | | | | | | | | | | | | | | * [Enum] reduce scope of new format behavior Instead of treating all Enums the same for format(), only user mixed-in enums will be affected. In other words, IntEnum and IntFlag will not be changing the format() behavior, due to the requirement that they be drop-in replacements of existing integer constants. If a user creates their own integer-based enum, then the new behavior will apply: class Grades(int, Enum): A = 5 B = 4 C = 3 D = 2 F = 0 Now: format(Grades.B) -> DeprecationWarning and '4' 3.12: -> no warning, and 'B'
* bpo-44342: [Enum] sync current docs to 3.10 (GH-26750)Ethan Furman2021-06-161-1/+1
|
* bpo-44242: [Enum] remove missing bits test from Flag creation (GH-26586)Ethan Furman2021-06-091-4/+82
| | | | Move the check for missing named flags in flag aliases from Flag creation to a new *verify* decorator.
* Remove duplicate words in docs. (GH-26167)Mariusz Felisiak2021-05-211-2/+2
|
* bpo-38250: add version added for FlagBoundary (GH-25820)Shantanu2021-05-141-0/+5
| | | | | | | * bpo-38250: add version added for FlagBoundary * Also add versionadded for utilities Co-authored-by: hauntsaninja <>
* fix enum.property reference in docs (GH-25875)Jelle Zijlstra2021-05-041-1/+1
|
* bpo-43957: [Enum] Deprecate ``TypeError`` from containment checks. (GH-25670)Ethan Furman2021-04-271-0/+6
| | | | | In 3.12 ``True`` or ``False`` will be returned for all containment checks, with ``True`` being returned if the value is either a member of that enum or one of its members' value.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: * `_simple_enum` decorator to transform a normal class into an enum * `_test_simple_enum` function to compare * `_old_convert_` to enable checking `_convert_` generated enums `_simple_enum` takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 `_old_convert_` works much like` _convert_` does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) `_test_simple_enum` takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)Ethan Furman2021-04-201-0/+1
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: _simple_enum decorator to transform a normal class into an enum _test_simple_enum function to compare _old_convert_ to enable checking _convert_ generated enums _simple_enum takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 _old_convert_ works much like _convert_ does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) test_simple_enum takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Enum: add (re)import of Flag for doctests (GH-25118)Ethan Furman2021-03-311-4/+4
| | | Fix issue with CI doctest forgetting that ``Flag`` had already been imported.
* bpo-40066: Enum: modify `repr()` and `str()` (GH-22392)Ethan Furman2021-03-311-1197/+441
| | | | | | | | | * Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
* bpo-43162: [Enum] update docs, renable doc tests (GH-24487)Ethan Furman2021-03-031-5/+6
| | | | * update docs, renable doc tests * make deprecation warning active for two releases
* Fix grammar in enum documentation. (GH-24689)Mariatta Wijaya2021-03-011-1/+1
| | | | | | There is an extra `s` in the singular word `method`. Reported in docs mailing list by Steven Nguyen. Automerge-Triggered-By: GH:Mariatta
* Fix minor typo in the rest format in the enum docs (GH-24335)Pablo Galindo2021-01-251-1/+1
|
* bpo-38250: [Enum] single-bit flags are canonical (GH-24215)Ethan Furman2021-01-251-27/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Flag members are now divided by one-bit verses multi-bit, with multi-bit being treated as aliases. Iterating over a flag only returns the contained single-bit flags. Iterating, repr(), and str() show members in definition order. When constructing combined-member flags, any extra integer values are either discarded (CONFORM), turned into ints (EJECT) or treated as errors (STRICT). Flag classes can specify which of those three behaviors is desired: >>> class Test(Flag, boundary=CONFORM): ... ONE = 1 ... TWO = 2 ... >>> Test(5) <Test.ONE: 1> Besides the three above behaviors, there is also KEEP, which should not be used unless necessary -- for example, _convert_ specifies KEEP as there are flag sets in the stdlib that are incomplete and/or inconsistent (e.g. ssl.Options). KEEP will, as the name suggests, keep all bits; however, iterating over a flag with extra bits will only return the canonical flags contained, not the extra bits. Iteration is now in member definition order. If member definition order matches increasing value order, then a more efficient method of flag decomposition is used; otherwise, sort() is called on the results of that method to get definition order. ``re`` module: repr() has been modified to support as closely as possible its previous output; the big difference is that inverted flags cannot be output as before because the inversion operation now always returns the comparable positive result; i.e. re.A|re.I|re.M|re.S is ~(re.L|re.U|re.S|re.T|re.DEBUG) in both of the above terms, the ``value`` is 282. re's tests have been updated to reflect the modifications to repr().
* [doc] Fix a few margins due to bad markup (GH-23619)Andre Delfino2020-12-171-1/+1
|
* bpo-42385: [Enum] add `_generate_next_value_` to StrEnum (GH-23735)Ethan Furman2020-12-101-2/+4
| | | The default for auto() is to return an integer, which doesn't work for `StrEnum`. The new `_generate_next_value_` for `StrEnum` returns the member name, lower cased.
* bpo-42517: [Enum] do not convert private names into members (GH-23722)Ethan Furman2020-12-101-0/+9
| | | private names, such as `_Color__hue` and `_Color__hue_` are now normal attributes, and do not become members nor raise exceptions
* bpo-41816: `StrEnum.__str__` is `str.__str__` (GH-22362)Ethan Furman2020-09-221-0/+15
| | | use `str.__str__` for `StrEnum` so that `str(StrEnum.member)` is the same as directly accessing the string value of the `StrEnum` member
* Enum: add extended AutoNumber example (GH-22349)Ethan Furman2020-09-221-0/+26
|
* bpo-41816: add `StrEnum` (GH-22337)Ethan Furman2020-09-221-0/+38
| | | | `StrEnum` ensures that its members were already strings, or intended to be strings.
* Enum: make `Flag` and `IntFlag` members iterable (GH-22221)Ethan Furman2020-09-161-0/+15
|