bpo-41811: create SortKey members using first given value (GH-22316)

This commit is contained in:
Ethan Furman 2020-09-19 11:12:57 -07:00 committed by GitHub
parent 2b05361bf7
commit ae0d2a33ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -45,9 +45,9 @@ class SortKey(str, Enum):
TIME = 'time', 'tottime'
def __new__(cls, *values):
obj = str.__new__(cls)
obj._value_ = values[0]
value = values[0]
obj = str.__new__(cls, value)
obj._value_ = value
for other_value in values[1:]:
cls._value2member_map_[other_value] = obj
obj._all_values = values

View File

@ -95,5 +95,9 @@ class StatsTestCase(unittest.TestCase):
self.assertIn('pass2', funcs_called)
self.assertIn('pass3', funcs_called)
def test_SortKey_enum(self):
self.assertEqual(SortKey.FILENAME, 'filename')
self.assertNotEqual(SortKey.FILENAME, SortKey.CALLS)
if __name__ == "__main__":
unittest.main()