| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
| |
(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'
|
| | |
|
| | |
|
| | |
|
| |
|
|
|
|
|
| |
In an inheritance chain of
int -> my_int -> final_int
the data type is now final_int (not my_int)
|
| |
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
(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
|
| |
|
|
| |
Move the check for missing named flags in flag aliases from Flag creation
to a new *verify* decorator.
|
| | |
|
| |
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|