summaryrefslogtreecommitdiffstats
path: root/Doc/library/enum.rst
Commit message (Collapse)AuthorAgeFilesLines
* [3.10] bpo-44559: [Enum] revert enum module to 3.9 (GH-27010)Ethan Furman2021-07-041-549/+1017
| | | * [Enum] revert enum module to 3.9
* [3.10] bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752) Ethan Furman2021-06-181-4/+30
| | | | | | | | | | | | | | | | | | | | | | | | | * [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'. (cherry picked from commit f60b07ab6c943fce084772c3c7731ab3bbd213ff) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* [3.10] bpo-44342: [Enum] improve test, add andrei kulakov to ACKS (GH-26726)Ethan Furman2021-06-161-1/+1
| | | | | | * [3.10] [Enum] improve test, add andrei kulakov to ACKS (GH-26726). (cherry picked from commit cb2014f2077c92c35486bf0db7e646a68478a7a5) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* [3.10] bpo-44242: [Enum] remove missing bits test from Flag creation ↵Ethan Furman2021-06-101-3/+82
| | | | | | | | | | (GH-26586) (GH-26635) Move the check for missing named flags in flag aliases from Flag creation to a new *verify* decorator.. (cherry picked from commit eea8148b7dff5ffc7b84433859ac819b1d92a74d) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* Remove duplicate words in docs. (GH-26167) (GH-26296)Miss Islington (bot)2021-05-221-2/+2
| | | | | (cherry picked from commit b06ed1d883cd79c920c514d8a1f4643cf93dc5e0) Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* fix enum.property reference in docs (GH-25875) (#25876)Miss Islington (bot)2021-05-041-1/+1
| | | | | (cherry picked from commit 6fee0835cb00677acd341751f831ca1af128f4c9) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* 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
|
* bpo-40721: add note about enum member name case (GH-22231)Ethan Furman2020-09-141-0/+6
| | | * UPPER_CASE preferred as enum members are constants
* bpo-40204: Add :noindex: in the documentation (GH-21859)Victor Stinner2020-08-131-0/+1
| | | | | | | | | | Add :noindex: to duplicated documentation to fix "duplicate object description" errors. For example, fix this Sphinx 3 issue: Doc/library/configparser.rst:1146: WARNING: duplicate object description of configparser.ConfigParser.optionxform, other instance in library/configparser, use :noindex: for one of them
* Remove trailing >>> in enum docs (GH-21358)E-Paine2020-07-091-1/+0
| | | The >>> as the last line serve no purpose and are not colored correctly by Sphinx.
* bpo-40025: Require _generate_next_value_ to be defined before members (GH-19098)Ethan Onstott2020-04-281-0/+4
| | | require `_generate_next_value_` to be defined before members
* bpo-39234: `enum.auto()` default initial value as 1 (GH-17878)YoSTEALTH2020-01-061-1/+1
| | | | | | | | | | Updated as Eric mentioned "By default, the initial value starts at 1" https://bugs.python.org/issue39234 Automerge-Triggered-By: @ericvsmith
* bpo-39234: Doc: `enum.auto()` incrementation value not specified. (GH-17872)YoSTEALTH2020-01-061-1/+1
| | | * `enum.auto()` initial value is now specified as being `1`.
* Minor documentation fixes on library/enum (GH-15234)Antoine2019-08-201-5/+4
| | | * Minor documentation fixes on library/enum
* bpo-37479: on Enum subclasses with mixins, __format__ uses overridden ↵thatneat2019-07-041-3/+5
| | | | | __str__ (GH-14545) * bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__
* Fix typo: class declaration (GH-11678)nu_no2019-01-271-1/+1
|
* bpo-29577: Enum: mixin classes don't mix well with already mixed Enums (GH-9328)Ethan Furman2018-09-221-3/+10
| | | * bpo-29577: allow multiple mixin classes
* bpo-33437: add __new__ vs __init__ example (GH-9145)Ethan Furman2018-09-121-0/+31
| | | | | | Improve Enum docs. https://bugs.python.org/issue33437
* bpo-33217: Raise TypeError for non-Enum lookups in Enums (GH-6651)Rahul Jha2018-09-101-1/+1
| | | * bpo-33217: Raise TypeError for non-Enum lookups in Enums
* Fix moduleauthor/sectionauthor directives in Enum (GH-8117)Andrés Delfino2018-07-071-4/+4
|
* bpo-33866: enum: Stop using OrderedDict (GH-7698)INADA Naoki2018-06-181-2/+2
|
* bpo-31801: Enum: add _ignore_ as class option (#5237)Ethan Furman2018-01-221-1/+25
| | | | | | | | | | | | | | | | * bpo-31801: Enum: add _ignore_ as class option _ignore_ is a list, or white-space seperated str, of names that will not be candidates for members; these names, and _ignore_ itself, are removed from the final class. * bpo-31801: Enum: add documentation for _ignore_ * bpo-31801: Enum: remove trailing whitespace * bpo-31801: Enum: fix bulleted list format * bpo-31801: add version added for _ignore_
* Improve enum.Flag code example (GH-5167)Julian Kahnert2018-01-131-1/+1
| | | | The code example that demonstrate how to use enum.Flag was missing the import of enum.auto.
* correct documentation for enum.html (#358)Kartik Anand2017-02-281-2/+2
|
* Issue #29129: Fix typo in "Using auto" sectionBerker Peksag2017-01-021-1/+1
|
* close issue28172: Change all example enum member names to uppercase, per ↵Ethan Furman2016-11-211-172/+173
| | | | Guido; patch by Chris Angelico.
* issue23591: fix flag decomposition and reprEthan Furman2016-09-181-0/+22
|
* issue23591: add auto() for auto-generating Enum member valuesEthan Furman2016-09-111-16/+83
|
* improve Enum docsEthan Furman2016-09-081-11/+12
|
* add recipes for pseudo-valueless enumsEthan Furman2016-09-071-11/+68
|
* issue23591: more docs; slight change to reprEthan Furman2016-09-041-1/+12
|
* issue23591: bool(empty_flags) == False; more docs & testsEthan Furman2016-09-021-3/+59
|
* issue23591: add docs; code cleanup; more testsEthan Furman2016-09-021-46/+127
|
* issue26981: add _order_ compatibility shim to enum.EnumEthan Furman2016-08-201-1/+20
|