Commit Graph

199 Commits

Author SHA1 Message Date
Miss Islington (bot) da40fa3526
[3.13] gh-120361: Add `nonmember` test with enum flags inside to `test_enum` (GH-120364) (#120511)
gh-120361: Add `nonmember` test with enum flags inside to `test_enum` (GH-120364)

* gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
(cherry picked from commit 7fadfd82eb)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-14 22:08:21 +03:00
Ethan Furman e5521bcca9
gh-117663: [Enum] fix _simple_enum's detection of aliases (GH-117664) 2024-04-09 11:31:07 -07:00
Ethan Furman 06e29a224f
gh-116600: [Enum] fix global Flag repr (GH-116615)
* and fix global flag repr

* Update Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-03-11 15:41:53 -07:00
Ethan Furman 3c0dcef980
gh-116040: [Enum] fix test_empty_names test (GH-116508)
* and fix _not_given usage
2024-03-11 13:42:01 -07:00
Ethan Furman 13ffd4bd9f
gh-116040: [Enum] fix by-value calls when second value is falsey; e.g. Cardinal(1, 0) (GH-116072) 2024-03-07 13:30:26 -08:00
Ethan Furman 3ea78fd5bc
gh-115821: [Enum] better error message for calling super().__new__() (GH-116063)
docs now state to not call super().__new__
if super().__new__ is called, a better error message is now used
2024-02-28 15:17:49 -08:00
Jason Zhang c2cb31bbe1
gh-115539: Allow enum.Flag to have None members (GH-115636) 2024-02-19 14:36:11 -08:00
Serhiy Storchaka ca3604a3e3
gh-115252: Fix test_enum with -OO mode again (GH-115334) 2024-02-13 12:21:20 +02:00
Serhiy Storchaka 2939ad02be
gh-97959: Fix rendering of routines in pydoc (GH-113941)
* Class methods no longer have "method of builtins.type instance" note.
* Corresponding notes are now added for class and unbound methods.
* Method and function aliases now have references to the module or the
  class where the origin was defined if it differs from the current.
* Bound methods are now listed in the static methods section.
* Methods of builtin classes are now supported as well as methods of
  Python classes.
2024-02-11 15:19:44 +02:00
Nikita Sobolev 33f56b7432
gh-115252: Fix `test_enum` with `-OO` mode (GH-115253) 2024-02-10 10:34:22 -08:00
Ethan Furman ff7588b729
gh-114071: [Enum] update docs and code for tuples/subclasses (GH-114871)
Update documentation with `__new__` and `__init__` entries.

Support use of `auto()` in tuple subclasses on member assignment lines.  Previously, auto() was only supported on the member definition line either solo or as part of a tuple:

    RED = auto()
    BLUE = auto(), 'azul'

However, since Python itself supports using tuple subclasses where tuples are expected, e.g.:

    from collections import namedtuple
    T = namedtuple('T', 'first second third')

    def test(one, two, three):
        print(one, two, three)

    test(*T(4, 5, 6))
    # 4 5 6

it made sense to also support tuple subclasses in enum definitions.
2024-02-04 07:22:55 -08:00
Ethan Furman 4c7e09d012
gh-114149: [Enum] revert #114160 and add more tuple-subclass tests (GH-114215)
This reverts commit 05e142b154.
2024-01-17 16:31:00 -08:00
Ethan Furman 33b47a2c28
gh-114149: [Enum] fix tuple subclass handling when using custom __new__ (GH-114160) 2024-01-17 09:47:11 -08:00
Ethan Furman de6bca9564
gh-112328: [Enum] Make some private attributes public. (GH-112514)
* [Enum] Make some private attributes public.

- ``_EnumDict`` --> ``EnumDict``
- ``EnumDict._member_names`` --> ``EnumDict.member_names``
- ``Enum._add_alias_``
- ``Enum._add_value_alias_``

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-12-05 08:27:36 -08:00
Nikita Sobolev c4dc5a6ae8
gh-111181: Fix enum doctests (GH-111180)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2023-10-30 12:56:29 -07:00
Pieter Eendebak a77180e663
gh-110905: [Enum] minor fixes and cleanup (GH-110906) 2023-10-16 13:37:54 -07:00
Ethan Furman c74e440168
gh-109022: [Enum] require `names=()` to create empty enum type (GH-109048)
add guard so that ``Enum('bar')`` raises a TypeError instead of
creating a new enum class called `bar`.  To create the new but
empty class, use:

    huh = Enum('bar', names=())
2023-09-07 18:19:03 -07:00
Nikita Sobolev b4c8cce9a7
gh-108840: Remove unused `TestEnumTypeSubclassing` from `test_enum` (#108841) 2023-09-05 09:45:54 +01:00
Ethan Furman d48760b2f1
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)
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.
2023-08-31 12:45:12 -07:00
Serhiy Storchaka bc5356bb5d
gh-108494: Argument Clinic: fix support of Limited C API (GH-108536) 2023-08-28 16:04:27 +03:00
Nikita Sobolev 199438b7cc
gh-105522: [Enum] Correctly handle possible exceptions during testing (GH-105523) 2023-08-16 12:17:28 -07:00
Prince Roshan 357e9e9da3
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666) 2023-07-12 14:01:17 -07:00
Ethan Furman 95b7426f45
gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist (#106468)
For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
2023-07-11 13:35:54 +02:00
Ethan Furman 59f009e589
gh-105497: [Enum] Fix Flag inversion when alias/mask members exist. (GH-105542)
When inverting a Flag member (or boundary STRICT), only consider other canonical flags; when inverting an IntFlag member (or boundary KEEP), also consider aliases.
2023-06-09 08:56:05 -07:00
Nikita Sobolev 4ff5690e59
gh-105332: [Enum] Fix unpickling flags in edge-cases (GH-105348)
* revert enum pickling from by-name to by-value

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2023-06-08 11:40:15 -07:00
Ethan Furman 5ecd8c85f9
gh-104764: [Enum] fix 3.13-specific tests (GH-104779) 2023-05-22 18:59:40 -07:00
T. Wouters 586aca3fc6
gh-104764: Skip failing tests in test_enum that started failing. (#104765)
Skip failing tests in test_enum that started failing when the version was bumped to 3.13.
2023-05-23 01:17:06 +02:00
Ethan Furman 700ec657c8
gh-103596: [Enum] do not shadow mixed-in methods/attributes (GH-103600)
For example:

    class Book(StrEnum):
        title = auto()
        author = auto()
        desc = auto()

    Book.author.desc is Book.desc

but

    Book.author.title() == 'Author'

is commonly expected.  Using upper-case member names avoids this confusion and possible performance impacts.

Co-authored-by: samypr100 <3933065+samypr100@users.noreply.github.com>
2023-04-18 16:19:23 -07:00
Ethan Furman a6f95941a3
gh-103479: [Enum] require __new__ to be considered a data type (GH-103495)
a mixin must either have a __new__ method, or be a dataclass, to be interpreted as a data-type
2023-04-13 08:31:03 -07:00
Ethan Furman 2194071540
gh-103365: [Enum] STRICT boundary corrections (GH-103494)
STRICT boundary:

- fix bitwise operations
- make default for Flag
2023-04-13 08:24:33 -07:00
Ethan Furman 4ec8dd10bd
gh-93910: [Enum] remove member.member deprecation (GH-103236)
i.e. Color.RED.BLUE is now officially supported.
2023-04-05 17:33:52 -07:00
Ethan Furman 2a4d8c0a9e
gh-102549: [Enum] fail enum creation when data type raises in __init__ (GH-103149) 2023-03-31 13:52:31 -07:00
Ethan Furman f4ed2c6ae5
gh-102558: [Enum] better handling of non-Enum EnumType classes (GH-103060) 2023-03-27 16:26:16 -07:00
Ethan Furman b838d80085
gh-103056: [Enum] ensure final _generate_next_value_ is a staticmethod (GH-103062) 2023-03-27 16:25:19 -07:00
Dong-hee Na bd063756b3
gh-102558: [Enum] fix AttributeError during member repr() (GH-102601) 2023-03-23 13:30:18 -07:00
JosephSBoyle a028778d4c
Rename redundant enum tests so that they run (#102535) 2023-03-14 15:16:45 -07:00
Alex Waygood 401d7a7f00
gh-102515: Remove unused imports in the `Lib/` directory (#102516) 2023-03-08 11:45:38 +00:00
Ethan Furman ef7c2bfcf1
gh-101541: [Enum] create flag psuedo-member without calling original __new__ (GH-101590) 2023-02-05 19:29:06 -08:00
Ethan Furman a5a7cea202
gh-100039: enhance __signature__ to work with str and callables (GH-100168)
Callables should be either class- or static-methods.
Enum now uses the classmethod version to greatly improve the help
given for enums and flags.
2022-12-16 12:30:47 -08:00
Ethan Furman ded02ca54d
gh-100098: [Enum] insist on actual tuples, no subclasses, for auto (GH-100099)
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.
2022-12-07 22:58:08 -08:00
Nikita Sobolev 889b0b9bf9
[Enum] Remove unused code from `test_enum.py` (GH-96986) 2022-12-06 18:44:47 -08:00
Ethan Furman 679efbb080
gh-94943: [Enum] improve repr() when inheriting from a dataclass (GH-99740)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-12-06 13:43:41 -08:00
Nikita Sobolev 5cfb7d19f5
gh-99518: Fix escape symbol in `test_enum` (#99519) 2022-11-16 15:06:37 +01:00
Ethan Furman 65dab1506e
gh-92647: [Enum] use final status to determine lookup or create (GH-99500)
* 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>
2022-11-15 08:49:22 -08:00
Ethan Furman 0b4ffb08cc
gh-99248: [Enum] fix negative number infinite loop (GH-99256)
[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
2022-11-08 12:00:19 -08:00
Ethan Furman a71b117c3d
[Enum] add built-in property to test_test_simple_enum (GH-98453) 2022-11-06 12:03:42 -08:00
Ethan Furman 8feb7ab77c
gh-93464: [Enum] fix auto() failure during multiple assignment (GH-99148)
* 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')`
2022-11-05 18:01:08 -07:00
Ethan Furman b44372e03c
gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528) 2022-10-05 15:25:55 -07:00
Nikita Sobolev 9b58eaf98c
gh-95591: [Enum] use `_FlagTests` base class (GH-96475) 2022-09-20 16:08:39 -07:00
Ethan Furman 4e704d7847
gh-95077: [Enum] add code-based deprecation warnings for member.member access (GH-95083)
* issue deprecation warning for member.member access
* always store member property in current class
* remove __getattr__
2022-07-25 11:05:10 -07:00