summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
Commit message (Collapse)AuthorAgeFilesLines
* [Enum] update version TODO comment (GH-99458)Ethan Furman2022-11-141-1/+1
|
* gh-99248: [Enum] fix negative number infinite loop (GH-99256)Ethan Furman2022-11-081-1/+7
| | | | | | | | [Enum] fix negative number infinite loop - _iter_bits_lsb() now raises a ValueError if a negative number is passed in - verify() now skips checking negative numbers for named flags
* gh-93464: [Enum] fix auto() failure during multiple assignment (GH-99148)Ethan Furman2022-11-061-8/+25
| | | | | | * 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')`
* gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)Ethan Furman2022-10-051-1/+1
|
* [Enum] fix typos (GH-96285)wim glenn2022-09-201-2/+2
|
* gh-95149: Enhance `http.HTTPStatus` with properties that indicate the HTTP ↵Alexandru Mărășteanu2022-08-301-1/+1
| | | | status category (GH-95453)
* gh-95077: [Enum] add code-based deprecation warnings for member.member ↵Ethan Furman2022-07-251-45/+41
| | | | | | | access (GH-95083) * issue deprecation warning for member.member access * always store member property in current class * remove __getattr__
* Revert "gh-93910: [Enum] restore member.member restriction while keeping ↵Ethan Furman2022-07-181-8/+0
| | | | | performance boost (GH-94913)" (#94985) This reverts commit c20186c3972ff38577c4c5e32ca86748210983d2.
* gh-94601: [Enum] fix inheritance for __str__ and friends (GH-94942)Ethan Furman2022-07-181-5/+21
|
* gh-93910: [Enum] restore member.member restriction while keeping performance ↵Ethan Furman2022-07-171-0/+8
| | | | boost (GH-94913)
* gh-93910: Fix enum performance regression (GH-94614)Michael Droettboom2022-07-071-8/+9
| | | | | | | | | | | | | | This removes the performance regression in 3.11, **at the expense of not fixing the "bug" that allows accessing values from values** (e.g. `Color.RED.BLUE`). Using the benchmark @markshannon [presented](https://github.com/python/cpython/issues/93910#issuecomment-1165503032), the results are: | Version | Enum | Fast enum | Normal class | | --- | --- | --- | --- | | 3.10 | 2.04 | 0.59 | 0.56 | | 3.11 | 2.78 | 0.31 | 0.15 | | This PR | 1.30 | 0.32 | 0.16 | I share this mostly as information about the source of the regression, as this may be useful. It may be that the lower-risk approach for the beta is just to revert to a previously-known working state.
* gh-93820: Pickle enum.Flag by name (GH-93891)Serhiy Storchaka2022-06-261-1/+15
|
* [Enum] Remove automatic docstring generation (GH-94188)Sam Ezeh2022-06-231-105/+0
|
* [Enum] fix typo (GH-94158)Ethan Furman2022-06-231-8/+8
|
* gh-91456: [Enum] Deprecate default auto() behavior with mixed value types ↵Oscar R2022-06-231-8/+26
| | | | | | | (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>
* gh-88123: Implement new Enum __contains__ (GH-93298)Carl Bordum Hansen2022-06-221-18/+8
| | | Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* gh-93847: Fix repr of enum of generic aliases (GH-93885)Serhiy Storchaka2022-06-161-2/+2
|
* gh-93820: Fix copy() regression in enum.Flag (GH-93876)Christian Heimes2022-06-161-0/+3
| | | | | | | | GH-26658 introduced a regression in copy / pickle protocol for combined `enum.Flag`s. `copy.copy(re.A | re.I)` would fail with `AttributeError: ASCII|IGNORECASE`. `enum.Flag` now has a `__reduce_ex__()` method that reduces flags by combined value, not by combined name.
* gh-93250: [Enum] Change IntEnum boundary to KEEP for backwards compatibility ↵Ethan Furman2022-05-271-1/+1
| | | | | (GH-93302) In previous versions of Python if an IntEnum member was combined with another integer type value using a bit-wise operation, the resulting value would still be the IntEnum type. This change restores that behavior.
* gh-93035: [Enum] Fix IntFlag crash when no single-bit members (GH-93076)Tobin Yehle2022-05-251-1/+1
| | | `EnumType` attempts to create a custom docstring for each enum/flag, but that was failing with pathological flags that had no members (only multi-bit aliases).
* gh-93118: [Enum] fix error message (GH-93138)Ethan Furman2022-05-231-2/+3
| | | Include member names in error message.
* gh93107: [Enum] fix missing variable in global_str (GH-93107)Ethan Furman2022-05-231-0/+1
|
* [Enum] Remove redundant check for existing members. (GH-92590)Ethan Furman2022-05-101-3/+0
|
* gh-78157: [Enum] nested classes will not be members in 3.13 (GH-92366)Ethan Furman2022-05-061-4/+53
| | | | | | | - add member() and nonmember() functions - add deprecation warning for internal classes in enums not becoming members in 3.13 Co-authored-by: edwardcwang
* bpo-46477: [Enum] ensure Flag subclasses have correct bitwise methods (GH-30816)Ethan Furman2022-01-231-39/+41
|
* bpo-45535: [Enum] include special dunders in dir() (GH-30677)Ethan Furman2022-01-181-20/+13
| | | | | | | | | Include the `__dunders__` in `dir()` that make `Enum` special: - `__contains__` - `__getitem__` - `__iter__` - `__len__` - `__members__`
* bpo-40066: [Enum] skip failing doc test (GH-30637)Kumar Aditya2022-01-171-232/+371
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-171-371/+232
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-161-232/+371
| | | | | | | | | | | | | | | 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-46242: [Enum] better error message for extending `Enum` with members ↵Nikita Sobolev2022-01-141-5/+4
| | | | (GH-30357)
* bpo-46269: [Enum] remove special-casing of `__new__` in `EnumType.__dir__` ↵Nikita Sobolev2022-01-051-4/+0
| | | | (GH-30421)
* bpo-45535: Improve output of Enum ``dir()`` (GH-29316)Alex Waygood2021-12-021-11/+58
| | | | | | 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-45417: [Enum] fix quadratic behavior during creation (GH-28907)Carl Friedrich Bolz-Tereick2021-10-141-7/+14
| | | | | | | | | | | | Creating an Enum exhibited quadratic behavior based on the number of members in three places: - `EnumDict._member_names`: a list searched with each new member's name - member creation: a `for` loop checking each existing member to see if new member was a duplicate - `auto()` values: a list of all previous values in enum was copied before being sent to `_generate_next_value()` Two of those issues have been resolved: - `_EnumDict._member_names` is now a dictionary so lookups are fast - member creation tries a fast value lookup before falling back to the slower `for` loop lookup The third issue still remains, as `_generate_next_value_()` can be user-overridden and could corrupt the last values list if it were not copied.
* bpo-44929: [Enum] Fix global repr (GH-27789)Pablo Galindo Salgado2021-08-251-4/+15
| | | | | | | | | | | | * Fix typo in __repr__ code * Add more tests for global int flag reprs * use last module if multi-module string - when an enum's `__module__` contains several module names, only use the last one Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752)Ethan Furman2021-06-181-3/+31
| | | | | | | | | | | | | | | | | | | | | * [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
|
* Fix a typo in _make_class_unpicklable() docstring (GH-26729)andrei kulakov2021-06-151-1/+1
|
* bpo-44242: [Enum] improve error messages (GH-26669)Ethan Furman2021-06-111-12/+25
|
* bpo-44342: [Enum] fix data type search (GH-26667)Ethan Furman2021-06-111-1/+1
| | | | | | | In an inheritance chain of int -> my_int -> final_int the data type is now final_int (not my_int)
* bpo-44342: [Enum] changed pickling from by-value to by-name (GH-26658)Ethan Furman2021-06-101-21/+4
| | | | | | | by-value lookups could fail on complex enums, necessitating a check for __reduce__ and possibly sabotaging the final enum; by-name lookups should never fail, and sabotaging is no longer necessary for class-based enum creation.
* bpo-44356: [Enum] allow multiple data-type mixins if they are all the same ↵Ethan Furman2021-06-101-4/+4
| | | | | | | | | | | | | | (GH-26649) This enables, for example, two base Enums to both inherit from `str`, and then both be mixed into the same final Enum: class Str1Enum(str, Enum): # some behavior here class Str2Enum(str, Enum): # some more behavior here class FinalStrEnum(Str1Enum, Str2Enum): # this now works
* bpo-44242: [Enum] remove missing bits test from Flag creation (GH-26586)Ethan Furman2021-06-091-11/+96
| | | | Move the check for missing named flags in flag aliases from Flag creation to a new *verify* decorator.
* bpo-43957: Add a missins space to the new format enum warning (#25770)Pablo Galindo2021-05-011-1/+1
|
* bpo-43957: [Enum] Deprecate ``TypeError`` from containment checks. (GH-25670)Ethan Furman2021-04-271-9/+20
| | | | | 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-43945: [Enum] Deprecate non-standard mixin format() behavior (GH-25649)Ethan Furman2021-04-271-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | In 3.12 the enum member, not the member's value, will be used for format() calls. Format specifiers can be used to retain the current display of enum members: Example enumeration: class Color(IntEnum): RED = 1 GREEN = 2 BLUE = 3 Current behavior: f'{Color.RED}' --> '1' Future behavior: f'{Color.RED}' --> 'RED' Using d specifier: f'{Color.RED:d}' --> '1' Using specifiers can be done now and is future-compatible.
* bpo-38659: [Enum] do not check '_inverted_' during simple test (GH-25566)Ethan Furman2021-04-241-2/+2
| | | Depending on usage, it's possible for Flag members to have the _inverted_ attribute when they are testing, while the Flag being testing against will not have that attribute on its members -- so skip that comparison.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-7/+318
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-319/+7
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-7/+319
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* bpo-43744: [Enum] fix ``_is_private`` (GH-25349)Ethan Furman2021-04-151-2/+3
| | | | ``_is_private`` now returns ``False`` instead of raising an exception when enum name matches beginning of class name as used in a private variable