bpo-41811: create SortKey members using first given value (GH-22316) (GH-22326)
(cherry picked from commit ae0d2a33ec
)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
3acc403f21
commit
488e3eb70d
|
@ -43,9 +43,9 @@ class SortKey(str, Enum):
|
||||||
TIME = 'time', 'tottime'
|
TIME = 'time', 'tottime'
|
||||||
|
|
||||||
def __new__(cls, *values):
|
def __new__(cls, *values):
|
||||||
obj = str.__new__(cls)
|
value = values[0]
|
||||||
|
obj = str.__new__(cls, value)
|
||||||
obj._value_ = values[0]
|
obj._value_ = value
|
||||||
for other_value in values[1:]:
|
for other_value in values[1:]:
|
||||||
cls._value2member_map_[other_value] = obj
|
cls._value2member_map_[other_value] = obj
|
||||||
obj._all_values = values
|
obj._all_values = values
|
||||||
|
|
|
@ -76,5 +76,9 @@ class StatsTestCase(unittest.TestCase):
|
||||||
'calls')
|
'calls')
|
||||||
|
|
||||||
|
|
||||||
|
def test_SortKey_enum(self):
|
||||||
|
self.assertEqual(SortKey.FILENAME, 'filename')
|
||||||
|
self.assertNotEqual(SortKey.FILENAME, SortKey.CALLS)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue