New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create enum for pstats sorting options #73423
Comments
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 The patch for such a change would be trivial:
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
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' |
To keep backwards compatibility and lesson the burden on new code, simply make the value of the duplicate names be the same: cumulative = 'cumulative'
cumtime = 'cumulative' This way the standard name is 'cumulative' but 'cumtime' works as well. |
Mariatta, would you like to prepare a patch for this. Ethan and I will review it. |
I am taking up to create a patch/pull request for this to get it reviewed. |
Thank you, Ratnadeep. |
It's good to hear that you're working on it. You can go ahead with this. Anyways, I will be around to see and learn how you fix this issue :) |
Mariatta, is there any movement on this issue? Thanks! |
Marriatta, perhaps it is time to let Ratnadeep work on this issue? |
Thanks for checking in, Ethan. Sorry, since this was first assigned to me, I got pre-occupied with other issues and projects in the core-workflow. Ratnadeep, if you are still interested, please go ahead with this issue. I've unassigned myself. Thanks. |
I'd like to try to work on this one |
Can this one be closed since it was an enhancement and doesn't need to be backported? |
Thanks for catching that! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: