Message285178
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' | |
| Date | User | Action | Args | | 2017-01-11 01:31:34 | Thane Brimhall | set | recipients: + Thane Brimhall | | 2017-01-11 01:31:34 | Thane Brimhall | set | messageid: <1484098294.24.0.117553666266.issue29237@psf.upfronthosting.co.za> | | 2017-01-11 01:31:34 | Thane Brimhall | link | issue29237 messages | | 2017-01-11 01:31:32 | Thane Brimhall | create | | |