]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
tracemalloc: 'pretty top' example no longer changes the filename (GH-18903)
authorAdam Johnson <me@adamj.eu>
Tue, 10 Mar 2020 18:18:50 +0000 (18:18 +0000)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2020 18:18:50 +0000 (19:18 +0100)
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`.

Doc/library/tracemalloc.rst

index e423470036558fe186914e754c7e0f98c571ee55..3eee9457fb29a8dae35ef1e84a8b12780849cb93 100644 (file)
@@ -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)