Skip to content

Commit

Permalink
bpo-41811: create SortKey members using first given value (GH-22316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfurman committed Sep 19, 2020
1 parent 2b05361 commit ae0d2a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Lib/pstats.py
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_pstats.py
Expand Up @@ -95,5 +95,9 @@ def pass3(): pass
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()

0 comments on commit ae0d2a3

Please sign in to comment.