| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
| |
gh-111181: Fix enum doctests (GH-111180)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
(cherry picked from commit c4dc5a6ae8aa13abb743182df088f1a3526d1bcd)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
__new__ (GH-108704) (GH-108739)
When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. .
member = object.__new__(cls)
member = int.__new__(cls, value)
member = str.__new__(cls, value)
Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
(cherry picked from commit d48760b2f1e28dd3c1a35721939f400a8ab619b8)
|
|
|
|
|
|
| |
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666)
(cherry picked from commit 357e9e9da3929cb9d55ea31896e66f488e44e8f2)
Co-authored-by: Prince Roshan <princekrroshan01@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-106468) (#106621)
gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist (GH-106468)
For example:
class Flag(enum.Flag):
A = 0x01
B = 0x02
MASK = 0xff
~Flag.MASK is Flag(0)
(cherry picked from commit 95b7426f45edb570869a5513c142f29ed9f851a1)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
| |
(GH-105542) (#105571)
When inverting a Flag member (or boundary STRICT), only consider other canonical flags; when inverting an IntFlag member (or boundary KEEP), also consider aliases.
(cherry picked from commit 59f009e5898a006cdc8f5249be589de6edfe5cd0)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
|
| |
(GH-105519)
* revert enum pickling from by-name to by-value
(cherry picked from commit 4ff5690e591b7d11cf11e34bf61004e2ea58ab3c)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
| |
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279)
(cherry picked from commit f4e2049f14d40c1b893c68530eec5e341cf3d929)
Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
|
|
|
|
|
|
|
|
| |
(GH-103495) (GH-103514)
a mixin must either have a __new__ method, or be a dataclass, to be interpreted as a data-type; an __init__ method is not enough (restores pre-3.11 behavior for non-dataclasses).
(cherry picked from commit a6f95941a3d686707fb38e0f37758e666f25e180)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
| |
STRICT boundary:
- fix bitwise operations
- make default for Flag
(cherry picked from commit 2194071540313e2bbdc7214d77453b9ce3034a5c)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
| |
i.e. Color.RED.BLUE is now officially supported..
(cherry picked from commit 4ec8dd10bd4682793559c4eccbcf6ae00688c4c3)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
| |
(GH-103149)
(cherry picked from commit 2a4d8c0a9e88f45047da640ce5a92b304d2d39b1)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
| |
fix FlagBoundary statements
add warning about reloading modules and enum identity
(cherry picked from commit 5ffc1e5a21de9a30566095386236db44695d184a)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
| |
(cherry picked from commit f4ed2c6ae5915329e49b9f94033ef182400e29fa)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
| |
(cherry picked from commit bd063756b34003c1bc7cacf5b1bd90a409180fb6)
Co-authored-by: Dong-hee Na <donghee.na@python.org>
|
|
|
|
|
|
|
| |
(GH-101590)
(cherry picked from commit ef7c2bfcf1fd618438f981ace64499a99ae9fae0)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
| |
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.
(cherry picked from commit ded02ca54d7bfa32c8eab0871d56e4547cd356eb)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
| |
(cherry picked from commit db115682bd639a2642c617f0b7d5b30cd7d7f472)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
|
|
| |
[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
(cherry picked from commit 0b4ffb08ccdc21fc07ce90d3f78b58a25e1af653)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
| |
* 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')`
(cherry picked from commit 8feb7ab77c80968a6de6079299a39b0494b1701b)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
| |
(cherry picked from commit b44372e03c5461b6ad3d89763a9eb6cb82df07a4)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
| |
(cherry picked from commit 58882640d631b0be0d81156928de97c2b3556f45)
Co-authored-by: wim glenn <wim.glenn@gmail.com>
|
|
|
|
|
|
|
| |
The builtin `property` is not a callable, so was failing the check in
`_test_simple_enum` causing a match failure; this adds `property` to the
bypass list.
Co-authored-by: Alexandru Mărășteanu <alexei@users.noreply.github.com>
|
|
|
|
|
| |
performance boost (GH-94913)" (#94981)
This reverts commit 30f28ac296e506b336e0ab56c41422a53c36d0c2.
|
|
|
|
|
| |
(cherry picked from commit c961d14f85a0e3e53d5ad1182206ef34030f10b8)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
| |
boost (GH-94913)
(cherry picked from commit c20186c3972ff38577c4c5e32ca86748210983d2)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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/93910GH-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.
(cherry picked from commit ed136b96737fdbeff864079d12904cb962c6cce5)
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
|
|
|
|
|
| |
(cherry picked from commit 536985814a7116f14c9bc90aa1b3e3d36d5b2367)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
|
| |
(cherry picked from commit 28a2ccfff279867b87aa31f56bfc97cf3d6b3afe)
Co-authored-by: Sam Ezeh <sam.z.ezeh@gmail.com>
|
|
|
|
|
| |
(cherry picked from commit b4e0d6124a848a22df1ba12891329242c9e96f11)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
|
|
| |
(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>
(cherry picked from commit fb1e9506c14ef32d5bec126dad6fa769c8c054f6)
Co-authored-by: Oscar R <89599049+oscar-LT@users.noreply.github.com>
|
|
|
|
|
| |
(cherry picked from commit 138db8e48b0bb006b1561f8ec76ade97afc6cbd7)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
(cherry picked from commit 05b32c1c796d6c80479756ae898f488eac5f4f71)
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Christian Heimes <christian@python.org>
|
|
|
|
|
|
|
|
| |
(GH-93302) (GH-93304)
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.
(cherry picked from commit 70cfe56cafb2b549983f63d5d1a54654fe63c15c)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
|
| |
(GH-93076) (GH-93197)
`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).
(cherry picked from commit 08cfc3dabf0f81a4494cd0d697befc7d0dec77b7)
Co-authored-by: Tobin Yehle <tobinyehle@gmail.com>
|
|
|
|
| |
Include member names in error message.
(cherry picked from commit a49721ea075a18a7787ace6752b4eb0954e1b607)
|
|
|
|
|
| |
(cherry picked from commit 046df59658c9f64a9f0fc909ed62e92c6c4dd668)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
|
|
|
|
|
|
|
| |
- add member() and nonmember() functions
- add deprecation warning for internal classes in enums not
becoming members in 3.13
Co-authored-by: edwardcwang
|
| |
|
|
|
|
|
|
|
|
|
| |
Include the `__dunders__` in `dir()` that make `Enum` special:
- `__contains__`
- `__getitem__`
- `__iter__`
- `__len__`
- `__members__`
|
| |
|
|
|
|
|
| |
(GH-30632)
This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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`
|
|
|
|
| |
(GH-30357)
|
|
|
|
| |
(GH-30421)
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* [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'
|
| |
|
| |
|