diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-09-19 19:56:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-19 19:56:13 (GMT) |
commit | 0e4d526de47eae24b75f3623cd56bb0453fc8c74 (patch) | |
tree | b4986fe66af9876333cf252bea217407f6e6187d | |
parent | 9e73cac173e5e9010bd18c8334fffeee1cade3a4 (diff) | |
download | cpython-0e4d526de47eae24b75f3623cd56bb0453fc8c74.zip cpython-0e4d526de47eae24b75f3623cd56bb0453fc8c74.tar.gz cpython-0e4d526de47eae24b75f3623cd56bb0453fc8c74.tar.bz2 |
bpo-41811: create SortKey members using first given value (GH-22316) (GH-22325)
(cherry picked from commit ae0d2a33ec05aece939a959d36fcf1df1e210a08)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
-rw-r--r-- | Lib/pstats.py | 6 | ||||
-rw-r--r-- | Lib/test/test_pstats.py | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Lib/pstats.py b/Lib/pstats.py index e781b91..0f93ae0 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 10559de..4f78b99 100644 --- a/Lib/test/test_pstats.py +++ b/Lib/test/test_pstats.py @@ -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() |