[Python-checkins] tracemalloc: 'pretty top' example no longer changes the filename (GH-18903)

Miss Islington (bot) webhook-mailer at python.org
Tue Mar 10 14:26:25 EDT 2020


https://github.com/python/cpython/commit/b26ccfe3f989f87d4ae824eda8400ab796af8f8e
commit: b26ccfe3f989f87d4ae824eda8400ab796af8f8e
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-03-10T11:26:20-07:00
summary:

tracemalloc: 'pretty top' example no longer changes the filename (GH-18903)


I've used this recipe a couple times and the filename editing has always
been less than useful and something I've removed. This is because many
modules end up losing which package they are located in, e.g. `util/date.py`.
(cherry picked from commit d06eec218eac81225f9017951cddfc211fed9325)

Co-authored-by: Adam Johnson <me at adamj.eu>

files:
M Doc/library/tracemalloc.rst

diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst
index 2d327c0254099..000c0ee940590 100644
--- a/Doc/library/tracemalloc.rst
+++ b/Doc/library/tracemalloc.rst
@@ -202,10 +202,8 @@ ignoring ``<frozen importlib._bootstrap>`` and ``<unknown>`` files::
         print("Top %s lines" % limit)
         for index, stat in enumerate(top_stats[:limit], 1):
             frame = stat.traceback[0]
-            # replace "/path/to/module/file.py" with "module/file.py"
-            filename = os.sep.join(frame.filename.split(os.sep)[-2:])
             print("#%s: %s:%s: %.1f KiB"
-                  % (index, filename, frame.lineno, stat.size / 1024))
+                  % (index, frame.filename, frame.lineno, stat.size / 1024))
             line = linecache.getline(frame.filename, frame.lineno).strip()
             if line:
                 print('    %s' % line)



More information about the Python-checkins mailing list