From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 19 Sep 2020 19:56:30 +0000 (-0700) Subject: bpo-41811: create SortKey members using first given value (GH-22316) (GH-22326) X-Git-Tag: v3.8.6~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=488e3eb70d24d5ce55ae0d7aed13a3721d3eb8a1;p=thirdparty%2FPython%2Fcpython.git bpo-41811: create SortKey members using first given value (GH-22316) (GH-22326) (cherry picked from commit ae0d2a33ec05aece939a959d36fcf1df1e210a08) Co-authored-by: Ethan Furman --- diff --git a/Lib/pstats.py b/Lib/pstats.py index 4b419a8ecdb6..67a68ebe750b 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -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 diff --git a/Lib/test/test_pstats.py b/Lib/test/test_pstats.py index f835ce309a60..052a3b9c3d5e 100644 --- a/Lib/test/test_pstats.py +++ b/Lib/test/test_pstats.py @@ -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()