[Python-checkins] bpo-41811: create SortKey members using first given value (GH-22316)

Ethan Furman webhook-mailer at python.org
Sat Sep 19 14:13:24 EDT 2020


https://github.com/python/cpython/commit/ae0d2a33ec05aece939a959d36fcf1df1e210a08
commit: ae0d2a33ec05aece939a959d36fcf1df1e210a08
branch: master
author: Ethan Furman <ethan at stoneleaf.us>
committer: GitHub <noreply at github.com>
date: 2020-09-19T11:12:57-07:00
summary:

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

files:
M Lib/pstats.py
M Lib/test/test_pstats.py

diff --git a/Lib/pstats.py b/Lib/pstats.py
index e781b91c6052c..0f93ae02c9507 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -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
diff --git a/Lib/test/test_pstats.py b/Lib/test/test_pstats.py
index 10559deb6bcb2..4f78b99fd1cae 100644
--- a/Lib/test/test_pstats.py
+++ b/Lib/test/test_pstats.py
@@ -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()



More information about the Python-checkins mailing list