You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
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
assignee=Noneclosed_at=<Date2017-11-29.23:05:52.607>created_at=<Date2017-11-23.20:10:20.707>labels= ['3.7', 'type-feature', 'library']
title='tracemalloc.Traceback.format() should have an option to reverse the traceback'updated_at=<Date2017-11-29.23:05:52.606>user='https://github.com/pitrou'
Right now tracemalloc.Traceback.format() returns the frames in "most recent call first" order. This is not intuitive since ordinary Python tracebacks are displayed in "most recent call last" order. It would be nice to add a reverse argument to change that.
tracemalloc.Traceback contains "raw" data from the C _tracemalloc module. But since we are at Python level, we are free to change how data is rendered to user.
Since Antoine Pitrou was surprised by the current frame order in Traceback.format() ("This is not intuitive since ordinary Python tracebacks are displayed in "most recent call last" order"), what do you think of adding a new parameter but also **reverse frames by default**?
Maybe we can go further and even reverse frames in Traceback constructor? This is a backward incompatible change, but I don't think that a lot of code in the wild uses the tracemalloc *API*.
About the parameter name: I'm ok with "reverse". *But* if we reverse by default, the "reverse" name can be confusing. Maybe we can use a less confusing name like "most_recent_last=True" (or "most_recent_first=False")?
Note: The faulthandler module also dumps starting with the "(most recent call first)", but I don't want to change that. It's for technical reason: faulthandler is called when something really bad happens and so Python internal structures may be corrupted. Moreover, frames is a single chained list, it's hard to iterate over them in the backward order (especially in faulthandler code where heap memory allocations are denied).