mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-103056: [Enum] ensure final _generate_next_value_ is a staticmethod (GH-103062)
This commit is contained in:
parent
56d055a0d8
commit
b838d80085
3 changed files with 23 additions and 0 deletions
|
@ -270,6 +270,17 @@ class _EnumTests:
|
|||
first = auto()
|
||||
self.NewSubEnum = NewSubEnum
|
||||
#
|
||||
class LazyGNV(self.enum_type):
|
||||
def _generate_next_value_(name, start, last, values):
|
||||
pass
|
||||
self.LazyGNV = LazyGNV
|
||||
#
|
||||
class BusyGNV(self.enum_type):
|
||||
@staticmethod
|
||||
def _generate_next_value_(name, start, last, values):
|
||||
pass
|
||||
self.BusyGNV = BusyGNV
|
||||
#
|
||||
self.is_flag = False
|
||||
self.names = ['first', 'second', 'third']
|
||||
if issubclass(MainEnum, StrEnum):
|
||||
|
@ -466,6 +477,12 @@ class _EnumTests:
|
|||
Main = self.MainEnum
|
||||
self.assertIs(Main(Main.first), Main.first)
|
||||
|
||||
def test_gnv_is_static(self):
|
||||
lazy = self.LazyGNV
|
||||
busy = self.BusyGNV
|
||||
self.assertTrue(type(lazy.__dict__['_generate_next_value_']) is staticmethod)
|
||||
self.assertTrue(type(busy.__dict__['_generate_next_value_']) is staticmethod)
|
||||
|
||||
def test_hash(self):
|
||||
MainEnum = self.MainEnum
|
||||
mapping = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue