aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/enum.py
Commit message (Collapse)AuthorAge
* gh-101541: [Enum] create flag psuedo-member without calling original __new__ ↵Ethan Furman2023-02-05
| | | | (GH-101590)
* gh-101341: Remove unncessary enum._power_of_two function (gh-101342)Dong-hee Na2023-01-28
|
* gh-86682: Adds sys._getframemodulename as an alternative to using _getframe ↵Steve Dower2023-01-13
| | | | | (GH-99520) Also updates calls in collections, doctest, enum, and typing modules to use _getframemodulename first when available.
* gh-100039: enhance __signature__ to work with str and callables (GH-100168)Ethan Furman2022-12-16
| | | | | Callables should be either class- or static-methods. Enum now uses the classmethod version to greatly improve the help given for enums and flags.
* gh-100098: [Enum] insist on actual tuples, no subclasses, for auto (GH-100099)Ethan Furman2022-12-07
| | | | | | When checking for auto() instances, only top-level usage is supported, which means either alone or as part of a regular tuple. Other containers, such as lists, dicts, or namedtuples, will not have auto() transformed into a value.
* gh-92120: The docstring of enum.Enum is invalid in reST (GH-92122)Takeshi KOMIYA2022-12-07
| | | Closes #92120
* gh-94943: [Enum] improve repr() when inheriting from a dataclass (GH-99740)Ethan Furman2022-12-06
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* gh-92647: [Enum] use final status to determine lookup or create (GH-99500)Ethan Furman2022-11-15
| | | | | | | * use final status to determine lookup or create * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* [Enum] update version TODO comment (GH-99458)Ethan Furman2022-11-13
|
* gh-99248: [Enum] fix negative number infinite loop (GH-99256)Ethan Furman2022-11-08
| | | | | | | | [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-05
| | | | | | * 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-05
|
* [Enum] fix typos (GH-96285)wim glenn2022-09-20
|
* gh-95149: Enhance `http.HTTPStatus` with properties that indicate the HTTP ↵Alexandru Mărășteanu2022-08-30
| | | | status category (GH-95453)
* gh-95077: [Enum] add code-based deprecation warnings for member.member ↵Ethan Furman2022-07-25
| | | | | | | 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-18
| | | | | performance boost (GH-94913)" (#94985) This reverts commit c20186c3972ff38577c4c5e32ca86748210983d2.
* gh-94601: [Enum] fix inheritance for __str__ and friends (GH-94942)Ethan Furman2022-07-17
|
* gh-93910: [Enum] restore member.member restriction while keeping performance ↵Ethan Furman2022-07-16
| | | | boost (GH-94913)
* gh-93910: Fix enum performance regression (GH-94614)Michael Droettboom2022-07-07
| | | | | | | | | | | | | | 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-26
|
* [Enum] Remove automatic docstring generation (GH-94188)Sam Ezeh2022-06-23
|
* [Enum] fix typo (GH-94158)Ethan Furman2022-06-23
|
* gh-91456: [Enum] Deprecate default auto() behavior with mixed value types ↵Oscar R2022-06-22
| | | | | | | (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-22
| | | Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
* gh-93847: Fix repr of enum of generic aliases (GH-93885)Serhiy Storchaka2022-06-16
|
* gh-93820: Fix copy() regression in enum.Flag (GH-93876)Christian Heimes2022-06-15
| | | | | | | | 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-27
| | | | | (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-24
| | | `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-23
| | | Include member names in error message.
* gh93107: [Enum] fix missing variable in global_str (GH-93107)Ethan Furman2022-05-23
|
* [Enum] Remove redundant check for existing members. (GH-92590)Ethan Furman2022-05-09
|
* gh-78157: [Enum] nested classes will not be members in 3.13 (GH-92366)Ethan Furman2022-05-06
| | | | | | | - 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-22
|
* bpo-45535: [Enum] include special dunders in dir() (GH-30677)Ethan Furman2022-01-18
| | | | | | | | | 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-17
|
* Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" ↵Victor Stinner2022-01-17
| | | | | (GH-30632) This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
* bpo-40066: [Enum] update str() and format() output (GH-30582)Ethan Furman2022-01-15
| | | | | | | | | | | | | | | 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-14
| | | | (GH-30357)
* bpo-46269: [Enum] remove special-casing of `__new__` in `EnumType.__dir__` ↵Nikita Sobolev2022-01-05
| | | | (GH-30421)
* bpo-45535: Improve output of Enum ``dir()`` (GH-29316)Alex Waygood2021-12-02
| | | | | | 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-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-25
| | | | | | | | | | | | * 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-18
| | | | | | | | | | | | | | | | | | | | | * [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-15
|
* Fix a typo in _make_class_unpicklable() docstring (GH-26729)andrei kulakov2021-06-14
|
* bpo-44242: [Enum] improve error messages (GH-26669)Ethan Furman2021-06-11
|
* bpo-44342: [Enum] fix data type search (GH-26667)Ethan Furman2021-06-11
| | | | | | | 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-10
| | | | | | | 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-10
| | | | | | | | | | | | | | (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-09
| | | | Move the check for missing named flags in flag aliases from Flag creation to a new *verify* decorator.