]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41811: create SortKey members using first given value (GH-22316)
authorEthan Furman <ethan@stoneleaf.us>
Sat, 19 Sep 2020 18:12:57 +0000 (11:12 -0700)
committerGitHub <noreply@github.com>
Sat, 19 Sep 2020 18:12:57 +0000 (11:12 -0700)
Lib/pstats.py
Lib/test/test_pstats.py

index e781b91c6052cfdae924f547140cfc36cecffe14..0f93ae02c95074dfd6bddff780474d11c28a654c 100644 (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
index 10559deb6bcb23a91b5cc690e06337910b79cd71..4f78b99fd1cae79a3fa5c9b37de0a71a25c09abd 100644 (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()