From 5f2cfa4bb7dd5a96a2b823975fd8bce8880cf07d Mon Sep 17 00:00:00 2001 From: Daniel Harding Date: Thu, 21 Apr 2022 14:36:34 +0300 Subject: [PATCH 1/4] Update tidy_stacktrace() docstring. --- debug_toolbar/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index cc90cf4db..ea2a1f65a 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -47,12 +47,11 @@ def omit_path(path): def tidy_stacktrace(stack): """ - Clean up stacktrace and remove all entries that: - 1. Are part of Django (except contrib apps) - 2. Are part of socketserver (used by Django's dev server) - 3. Are the last entry (which is part of our stacktracing code) + Clean up stacktrace and remove all entries that are excluded by the + HIDE_IN_STACKTRACES setting. - ``stack`` should be a list of frame tuples from ``inspect.stack()`` + ``stack`` should be a list of frame tuples from ``inspect.stack()`` or + ``debug_toolbar.utils.get_stack()``. """ trace = [] for frame, path, line_no, func_name, text in (f[:5] for f in stack): From 6463356b6a018983e3ef46d00cd92533f15c3f31 Mon Sep 17 00:00:00 2001 From: Daniel Harding Date: Tue, 19 Apr 2022 17:20:08 +0300 Subject: [PATCH 2/4] Remove obsolete compatibility code inspect.Traceback has existed since Python 2.6. --- debug_toolbar/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index ea2a1f65a..2e5b5f263 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -222,10 +222,7 @@ def getframeinfo(frame, context=1): break lines = [line.decode(encoding, "replace") for line in lines] - if hasattr(inspect, "Traceback"): - return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index) - else: - return (filename, lineno, frame.f_code.co_name, lines, index) + return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index) def get_sorted_request_variable(variable): From 7a28c71e69d510704df3e709724357641c1f1ca1 Mon Sep 17 00:00:00 2001 From: Daniel Harding Date: Tue, 17 May 2022 16:29:27 +0300 Subject: [PATCH 3/4] Remove unnecessary decoding from getframeinfo() linecache uses tokenize.open() to detect and use the encoding of the file since Python 3.4. --- debug_toolbar/utils.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index 2e5b5f263..13f7472ad 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -1,6 +1,5 @@ import inspect import os.path -import re import sys from importlib import import_module from pprint import pformat @@ -200,27 +199,14 @@ def getframeinfo(frame, context=1): try: lines, lnum = inspect.findsource(frame) except Exception: # findsource raises platform-dependant exceptions - first_lines = lines = index = None + lines = index = None else: start = max(start, 1) start = max(0, min(start, len(lines) - context)) - first_lines = lines[:2] lines = lines[start : (start + context)] index = lineno - 1 - start else: - first_lines = lines = index = None - - # Code taken from Django's ExceptionReporter._get_lines_from_file - if first_lines and isinstance(first_lines[0], bytes): - encoding = "ascii" - for line in first_lines[:2]: - # File coding may be specified. Match pattern from PEP-263 - # (https://www.python.org/dev/peps/pep-0263/) - match = re.search(rb"coding[:=]\s*([-\w.]+)", line) - if match: - encoding = match.group(1).decode("ascii") - break - lines = [line.decode(encoding, "replace") for line in lines] + lines = index = None return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index) From 5ac81e7b464a7ed96c415ed3f5879f730459bc5e Mon Sep 17 00:00:00 2001 From: Daniel Harding Date: Sun, 29 May 2022 15:40:23 +0300 Subject: [PATCH 4/4] Update change log --- docs/changes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes.rst b/docs/changes.rst index 019a6eac3..7a7cc48fd 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -10,6 +10,7 @@ Change log * Added pyflame (for flame graphs) to the list of third-party panels. * Fixed the cache panel to correctly count cache misses from the get_many() cache method. +* Removed some obsolete compatibility code from the stack trace recording code. 3.4.0 (2022-05-03) ------------------