]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41811: create SortKey members using first given value (GH-22316) (GH-22326)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 19 Sep 2020 19:56:30 +0000 (12:56 -0700)
committerGitHub <noreply@github.com>
Sat, 19 Sep 2020 19:56:30 +0000 (12:56 -0700)
(cherry picked from commit ae0d2a33ec05aece939a959d36fcf1df1e210a08)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Lib/pstats.py
Lib/test/test_pstats.py

index 4b419a8ecdb6c785fb630d4e2ef208e60ab27a1c..67a68ebe750b582097d667e90fe14888389ba730 100644 (file)
@@ -43,9 +43,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 f835ce309a60e1130f1d43c35049f4be38cf98e5..052a3b9c3d5ee78c1902336906472bf7cf06470a 100644 (file)
@@ -76,5 +76,9 @@ class StatsTestCase(unittest.TestCase):
                           'calls')
 
 
+    def test_SortKey_enum(self):
+        self.assertEqual(SortKey.FILENAME, 'filename')
+        self.assertNotEqual(SortKey.FILENAME, SortKey.CALLS)
+
 if __name__ == "__main__":
     unittest.main()