summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-09-12 13:53:16 (GMT)
committerGitHub <noreply@github.com>2023-09-12 13:53:16 (GMT)
commitca848bbf78cf82447cc5c2fe6822c82f6f9e59c4 (patch)
tree6ea447912f1d9324f03a0d9dfe4e3bc57d1cac61 /Lib/test
parentd533ab17ec37b457a5cc286f30c7559e358492bf (diff)
downloadcpython-ca848bbf78cf82447cc5c2fe6822c82f6f9e59c4.zip
cpython-ca848bbf78cf82447cc5c2fe6822c82f6f9e59c4.tar.gz
cpython-ca848bbf78cf82447cc5c2fe6822c82f6f9e59c4.tar.bz2
[3.12] gh-109022: [Enum] require `names=()` to create empty enum type (GH-109048) (#109122)
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=()) (cherry picked from commit c74e440168fab9bf91346471087a394af13fa2db) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_enum.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index dc60cac..14f16f7 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -276,6 +276,7 @@ class _EnumTests:
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
+ self.NewBaseEnum = NewBaseEnum
class NewSubEnum(NewBaseEnum):
first = auto()
self.NewSubEnum = NewSubEnum
@@ -342,10 +343,8 @@ class _EnumTests:
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
- NewBaseEnum = self.enum_type('NewBaseEnum', dict(__format__=__format__, __str__=__str__))
- class NewSubEnum(NewBaseEnum):
- first = auto()
- self.NewSubEnum = NewBaseEnum('NewSubEnum', 'first')
+ self.NewBaseEnum = self.enum_type('NewBaseEnum', dict(__format__=__format__, __str__=__str__))
+ self.NewSubEnum = self.NewBaseEnum('NewSubEnum', 'first')
#
def _generate_next_value_(name, start, last, values):
pass
@@ -561,6 +560,10 @@ class _EnumTests:
self.assertTrue('description' not in dir(SubEnum))
self.assertTrue('description' in dir(SubEnum.sample), dir(SubEnum.sample))
+ def test_empty_enum_has_no_values(self):
+ with self.assertRaisesRegex(TypeError, "<.... 'NewBaseEnum'> has no members"):
+ self.NewBaseEnum(7)
+
def test_enum_in_enum_out(self):
Main = self.MainEnum
self.assertIs(Main(Main.first), Main.first)