This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Thane Brimhall
Recipients Thane Brimhall
Date 2017-01-11.01:31:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484098294.24.0.117553666266.issue29237@psf.upfronthosting.co.za>
In-reply-to
Content
When using the cProfile and pstats modules, I often forget which string keys are available for sorting. It would be nice to add an enum for these so a user could have their linter and IDE check that value pre-runtime. By subclassing both `str` and `Enum` this proposal would be backwards-compatible with all existing code. The patch for such a change would be trivial: 1. Add a new Sort class to the pstats module: class Sort(str, enum.Enum): calls = 'calls' # call count cumulative = 'cumulative' # cumulative time cumtime = 'cumtime' # cumulative time file = 'file' # file name filename = 'filename' # file name module = 'module' # file name ncalls = 'ncalls' # call count pcalls = 'pcalls' # primitive call count line = 'line' # line number name = 'name' # function name nfl = 'nfl' # name/file/line stdname = 'stdname' # standard name time = 'time' # internal time tottime = 'tottime' # internal time 2. Change the print_stats method signature on the profiler base and subclasses to look like this: def print_stats(self, sort: Sort=Sort.stdname): Optionally, you could build the Sort enum like below to remove redundant options and increase explicitness: class Sort(str, enum.Enum): call_count = 'calls' cumulative_time = 'cumulative' filename = 'filename' primitive_call_count = 'pcalls' line_number = 'line' function_name = 'name' name_file_line = 'nfl' standard_name = 'stdname' internal_time = 'time'
History
Date User Action Args
2017-01-11 01:31:34Thane Brimhallsetrecipients: + Thane Brimhall
2017-01-11 01:31:34Thane Brimhallsetmessageid: <1484098294.24.0.117553666266.issue29237@psf.upfronthosting.co.za>
2017-01-11 01:31:34Thane Brimhalllinkissue29237 messages
2017-01-11 01:31:32Thane Brimhallcreate