From d433f2186dd0f56c03f51b47a2b9dc3eba88dd3b Mon Sep 17 00:00:00 2001 From: nicky-eng Date: Sun, 23 Jul 2023 12:06:39 +0200 Subject: [PATCH 1/9] gh-105535 Document potential performance trap during enum creation --- Doc/library/enum.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index e9c4f0e2c5f59b..36b55610bb3a7a 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -267,6 +267,10 @@ Data Types appropriate value will be chosen for you. See :class:`auto` for the details. + If the value is not hashable, the enum creation will take quadratic time + relative to the number of members. + + .. attribute:: Enum._ignore_ ``_ignore_`` is only used during creation and is removed from the From 981eacaf432ea72f9496f4e0b5a77d41f8a25b30 Mon Sep 17 00:00:00 2001 From: nicky-eng Date: Sun, 23 Jul 2023 14:07:11 +0200 Subject: [PATCH 2/9] gh-105535: Add warning about quadratical growth --- Doc/library/enum.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 36b55610bb3a7a..41bd4b2c591995 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -267,8 +267,8 @@ Data Types appropriate value will be chosen for you. See :class:`auto` for the details. - If the value is not hashable, the enum creation will take quadratic time - relative to the number of members. + If the values are not hashable, be warned that the time required for enum + creation will grow quadratically with the number of members. .. attribute:: Enum._ignore_ From 6275352ed535c79b99c34027410d8afb89f52088 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 24 Jul 2023 11:45:25 -0700 Subject: [PATCH 3/9] Update Doc/library/enum.rst --- Doc/library/enum.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 41bd4b2c591995..de38897be5ada0 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -267,8 +267,9 @@ Data Types appropriate value will be chosen for you. See :class:`auto` for the details. - If the values are not hashable, be warned that the time required for enum - creation will grow quadratically with the number of members. + While mutable/unhashable values, such as :class:`dict` or :class:`list`, can + be used, they will have a quadratic performance impact relative to the total + number of mutable/unhashable values in the enum. .. attribute:: Enum._ignore_ From 94eba9adc962d7237ced2894a5bd36faf5ebabc8 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 24 Jul 2023 13:39:33 -0700 Subject: [PATCH 4/9] Update Doc/library/enum.rst --- Doc/library/enum.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index de38897be5ada0..4383d6f6d8563f 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -267,9 +267,10 @@ Data Types appropriate value will be chosen for you. See :class:`auto` for the details. - While mutable/unhashable values, such as :class:`dict` or :class:`list`, can - be used, they will have a quadratic performance impact relative to the total - number of mutable/unhashable values in the enum. + While mutable/unhashable values, such as :class:`dict`, :class:`list` or + a mutable :class:`dataclass`, can be used, they will have a quadratic + performance impact relative to the total number of mutable/unhashable + values in the enum. .. attribute:: Enum._ignore_ From c89ebd44cc1bef9b8d9e12581afbe89eff7bd26b Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 24 Jul 2023 17:06:54 -0700 Subject: [PATCH 5/9] Update Doc/library/enum.rst attempt to fix dataclass link --- Doc/library/enum.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 4383d6f6d8563f..0d6e225d792261 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -268,9 +268,9 @@ Data Types details. While mutable/unhashable values, such as :class:`dict`, :class:`list` or - a mutable :class:`dataclass`, can be used, they will have a quadratic - performance impact relative to the total number of mutable/unhashable - values in the enum. + a mutable :class:`~dataclasses.dataclass`, can be used, they will have a + quadratic performance impact relative to the total number of + mutable/unhashable values in the enum. .. attribute:: Enum._ignore_ From c8c74cda82cabbb9148f98fed2745a5e823800f6 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 4 Mar 2024 12:51:47 -0800 Subject: [PATCH 6/9] Update Doc/library/enum.rst --- Doc/library/enum.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 0d6e225d792261..5fa7788c80caa9 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -269,8 +269,8 @@ Data Types While mutable/unhashable values, such as :class:`dict`, :class:`list` or a mutable :class:`~dataclasses.dataclass`, can be used, they will have a - quadratic performance impact relative to the total number of - mutable/unhashable values in the enum. + quadratic performance impact during creation relative to the + total number of mutable/unhashable values in the enum. .. attribute:: Enum._ignore_ From f4051809ad3551becdb6f249fcad53eb9f45920c Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 4 Mar 2024 13:55:00 -0800 Subject: [PATCH 7/9] remove trailing whitespace --- Doc/library/enum.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index e5724f331c0326..1f0d3d9fb76837 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -278,9 +278,9 @@ Data Types >>> Color.RED.value 1 - + Value of the member, can be set in :meth:`~object.__new__`. - + .. note:: Enum member values Member values can be anything: :class:`int`, :class:`str`, etc. If From baf05a04849e221ae9a5e6eb63695de5c217b1c3 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Tue, 5 Mar 2024 08:56:00 -0800 Subject: [PATCH 8/9] re-add sunder versions of name and value Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/enum.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 1f0d3d9fb76837..94831236d65a30 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -293,6 +293,14 @@ Data Types quadratic performance impact during creation relative to the total number of mutable/unhashable values in the enum. +.. attribute:: Enum._name_ + + Name of the member. + + .. attribute:: Enum._value_ + + Value of the member, can be set in :meth:`~object.__new__`. + .. attribute:: Enum._order_ No longer used, kept for backward compatibility. From 43cc68c9afa7534cb534becfab793d36aefe5f66 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Tue, 5 Mar 2024 13:49:09 -0800 Subject: [PATCH 9/9] Update Doc/library/enum.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/enum.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 94831236d65a30..d84d9d9b4161b1 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -293,7 +293,7 @@ Data Types quadratic performance impact during creation relative to the total number of mutable/unhashable values in the enum. -.. attribute:: Enum._name_ + .. attribute:: Enum._name_ Name of the member.