Thread View
j: Next unread message
k: Previous unread message
j a: Jump to all threads
j l: Jump to MailingList overview
https://github.com/python/cpython/commit/863154c9292e70c5a8a1a3f22ef4ee42e2…
commit: 863154c9292e70c5a8a1a3f22ef4ee42e2304281
branch: main
author: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel(a)users.noreply.github.com>
date: 2021-08-31T21:42:08+01:00
summary:
bpo-31299: make it possible to filter out frames from tracebacks (GH-28067)
files:
A Misc/NEWS.d/next/Library/2021-08-30-13-55-09.bpo-31299.9QzjZs.rst
M Doc/library/traceback.rst
M Lib/test/test_traceback.py
M Lib/traceback.py
diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 83d5c8c6fcbd3..7b230495b7b56 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -357,7 +357,8 @@ capture data for later printing in a lightweight fashion.
Returns a string for printing one of the frames involved in the stack.
This method gets called for each frame object to be printed in the
- :class:`StackSummary`.
+ :class:`StackSummary`. If it returns ``None``, the frame is omitted
+ from the output.
.. versionadded:: 3.11
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 5d48e9d7ff039..d1967aabb29a1 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1514,6 +1514,34 @@ def some_inner():
s.format(),
[f'{__file__}:{some_inner.__code__.co_firstlineno + 1}'])
+ def test_dropping_frames(self):
+ def f():
+ 1/0
+
+ def g():
+ try:
+ f()
+ except:
+ return sys.exc_info()
+
+ exc_info = g()
+
+ class Skip_G(traceback.StackSummary):
+ def format_frame(self, frame):
+ if frame.name == 'g':
+ return None
+ return super().format_frame(frame)
+
+ stack = Skip_G.extract(
+ traceback.walk_tb(exc_info[2])).format()
+
+ self.assertEqual(len(stack), 1)
+ lno = f.__code__.co_firstlineno + 1
+ self.assertEqual(
+ stack[0],
+ f' File "{__file__}", line {lno}, in f\n 1/0\n'
+ )
+
class TestTracebackException(unittest.TestCase):
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 4ad8c9a17b349..8d83fd9b517e6 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -515,6 +515,9 @@ def format(self):
last_name = None
count = 0
for frame in self:
+ formatted_frame = self.format_frame(frame)
+ if formatted_frame is None:
+ continue
if (last_file is None or last_file != frame.filename or
last_line is None or last_line != frame.lineno or
last_name is None or last_name != frame.name):
diff --git a/Misc/NEWS.d/next/Library/2021-08-30-13-55-09.bpo-31299.9QzjZs.rst b/Misc/NEWS.d/next/Library/2021-08-30-13-55-09.bpo-31299.9QzjZs.rst
new file mode 100644
index 0000000000000..1ffa0b15172ee
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-08-30-13-55-09.bpo-31299.9QzjZs.rst
@@ -0,0 +1 @@
+Add option to completely drop frames from a traceback by returning ``None`` from a :meth:`~traceback.StackSummary.format_frame` override.
\ No newline at end of file
https://github.com/python/cpython/commit/2280bc116301d45efc4d69cea452d272fd…
commit: 2280bc116301d45efc4d69cea452d272fdcd05b1
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-08-31T12:24:48-07:00
summary:
bpo-45059: Add module cleanup to IDLE test_macosx (GH-28102)
(cherry picked from commit 22fe0eb13c3441b71b60aaea0e7fe289a29783da)
Co-authored-by: Terry Jan Reedy <tjreedy(a)udel.edu>
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index 1932477358689..86da8849e5ca0 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -12,6 +12,15 @@
alltypes = mactypes | nontypes
+def setUpModule():
+ global orig_tktype
+ orig_tktype = macosx._tk_type
+
+
+def tearDownModule():
+ macosx._tk_type = orig_tktype
+
+
class InitTktypeTest(unittest.TestCase):
"Test _init_tk_type."
https://github.com/python/cpython/commit/0f274cb2d78f71073e9d7295df3b9006e7…
commit: 0f274cb2d78f71073e9d7295df3b9006e7bf1097
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-08-31T12:21:28-07:00
summary:
bpo-45059: Add module cleanup to IDLE test_macosx (GH-28102)
(cherry picked from commit 22fe0eb13c3441b71b60aaea0e7fe289a29783da)
Co-authored-by: Terry Jan Reedy <tjreedy(a)udel.edu>
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index 1932477358689..86da8849e5ca0 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -12,6 +12,15 @@
alltypes = mactypes | nontypes
+def setUpModule():
+ global orig_tktype
+ orig_tktype = macosx._tk_type
+
+
+def tearDownModule():
+ macosx._tk_type = orig_tktype
+
+
class InitTktypeTest(unittest.TestCase):
"Test _init_tk_type."
https://github.com/python/cpython/commit/22fe0eb13c3441b71b60aaea0e7fe289a2…
commit: 22fe0eb13c3441b71b60aaea0e7fe289a29783da
branch: main
author: Terry Jan Reedy <tjreedy(a)udel.edu>
committer: terryjreedy <tjreedy(a)udel.edu>
date: 2021-08-31T14:59:35-04:00
summary:
bpo-45059: Add module cleanup to IDLE test_macosx (GH-28102)
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index 1932477358689..86da8849e5ca0 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -12,6 +12,15 @@
alltypes = mactypes | nontypes
+def setUpModule():
+ global orig_tktype
+ orig_tktype = macosx._tk_type
+
+
+def tearDownModule():
+ macosx._tk_type = orig_tktype
+
+
class InitTktypeTest(unittest.TestCase):
"Test _init_tk_type."
https://github.com/python/cpython/commit/ebbd0ac5d8850a1630090c210b2454b4b2…
commit: ebbd0ac5d8850a1630090c210b2454b4b26c7daa
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-08-31T11:08:32-07:00
summary:
bpo-45039: Consistently use ADDOP_LOAD_CONST in compiler rather than ADDOP_O(c, LOAD_CONST,...) (GH-28015)
(cherry picked from commit 70ccee418d1f9d34ed15cfe7104221f9cfd27d03)
Co-authored-by: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
files:
M Python/compile.c
diff --git a/Python/compile.c b/Python/compile.c
index d55b0beaec77c..baea4940d3724 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1568,12 +1568,14 @@ compiler_addop_j_noline(struct compiler *c, int opcode, basicblock *b)
}
#define ADDOP_O(C, OP, O, TYPE) { \
+ assert((OP) != LOAD_CONST); /* use ADDOP_LOAD_CONST */ \
if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) \
return 0; \
}
/* Same as ADDOP_O, but steals a reference. */
#define ADDOP_N(C, OP, O, TYPE) { \
+ assert((OP) != LOAD_CONST); /* use ADDOP_LOAD_CONST_NEW */ \
if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) { \
Py_DECREF((O)); \
return 0; \
@@ -1751,7 +1753,7 @@ compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b)
static int
compiler_call_exit_with_nones(struct compiler *c) {
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ ADDOP_LOAD_CONST(c, Py_None);
ADDOP(c, DUP_TOP);
ADDOP(c, DUP_TOP);
ADDOP_I(c, CALL_FUNCTION, 3);
@@ -5062,7 +5064,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
if(!compiler_call_exit_with_nones(c))
return 0;
ADDOP(c, GET_AWAITABLE);
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ ADDOP_LOAD_CONST(c, Py_None);
ADDOP(c, YIELD_FROM);
ADDOP(c, POP_TOP);
https://github.com/python/cpython/commit/c1db7598790d037e58cd99c06d5c166433…
commit: c1db7598790d037e58cd99c06d5c166433d63322
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-08-31T10:53:42-07:00
summary:
bpo-45059: Fix IDLE test typo: using "==" instead of "=" (GH-28086)
(cherry picked from commit 54f100514b02f6628450043e21ccfe39350d7ac7)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index b6bd922e4b99d..1932477358689 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -34,7 +34,7 @@ def test_init_sets_tktype(self):
for platform, types in ('darwin', alltypes), ('other', nontypes):
with self.subTest(platform=platform):
macosx.platform = platform
- macosx._tk_type == None
+ macosx._tk_type = None
macosx._init_tk_type()
self.assertIn(macosx._tk_type, types)
https://github.com/python/cpython/commit/337c8adf31c46b688a5f82bcb64dc6f1ad…
commit: 337c8adf31c46b688a5f82bcb64dc6f1ad56703d
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-08-31T10:50:42-07:00
summary:
bpo-45059: Fix IDLE test typo: using "==" instead of "=" (GH-28086)
(cherry picked from commit 54f100514b02f6628450043e21ccfe39350d7ac7)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index b6bd922e4b99dd..19324773586896 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -34,7 +34,7 @@ def test_init_sets_tktype(self):
for platform, types in ('darwin', alltypes), ('other', nontypes):
with self.subTest(platform=platform):
macosx.platform = platform
- macosx._tk_type == None
+ macosx._tk_type = None
macosx._init_tk_type()
self.assertIn(macosx._tk_type, types)
https://github.com/python/cpython/commit/2b76a5322fdf71d62b531fd765085f96f9…
commit: 2b76a5322fdf71d62b531fd765085f96f981c244
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2021-08-31T20:45:09+03:00
summary:
bpo-45057: Simplify RegressionTestResult (GH-28081)
Remove code which duplicates the functionality of TextTestResult.
files:
M Lib/test/support/testresult.py
diff --git a/Lib/test/support/testresult.py b/Lib/test/support/testresult.py
index 670afbea2659d..6f2edda0f580a 100644
--- a/Lib/test/support/testresult.py
+++ b/Lib/test/support/testresult.py
@@ -10,12 +10,11 @@
import unittest
class RegressionTestResult(unittest.TextTestResult):
- separator1 = '=' * 70 + '\n'
- separator2 = '-' * 70 + '\n'
USE_XML = False
def __init__(self, stream, descriptions, verbosity):
- super().__init__(stream=stream, descriptions=descriptions, verbosity=0)
+ super().__init__(stream=stream, descriptions=descriptions,
+ verbosity=2 if verbosity else 0)
self.buffer = True
if self.USE_XML:
from xml.etree import ElementTree as ET
@@ -25,8 +24,6 @@ def __init__(self, stream, descriptions, verbosity):
self.__suite.set('start', datetime.utcnow().isoformat(' '))
self.__e = None
self.__start_time = None
- self.__results = []
- self.__verbose = bool(verbosity)
@classmethod
def __getId(cls, test):
@@ -45,9 +42,6 @@ def startTest(self, test):
if self.USE_XML:
self.__e = e = self.__ET.SubElement(self.__suite, 'testcase')
self.__start_time = time.perf_counter()
- if self.__verbose:
- self.stream.write(f'{self.getDescription(test)} ... ')
- self.stream.flush()
def _add_result(self, test, capture=False, **args):
if not self.USE_XML:
@@ -85,10 +79,6 @@ def _add_result(self, test, capture=False, **args):
else:
e2.text = str(v)
- def __write(self, c, word):
- if self.__verbose:
- self.stream.write(f'{word}\n')
-
@classmethod
def __makeErrorDict(cls, err_type, err_value, err_tb):
if isinstance(err_type, type):
@@ -111,45 +101,26 @@ def __makeErrorDict(cls, err_type, err_value, err_tb):
def addError(self, test, err):
self._add_result(test, True, error=self.__makeErrorDict(*err))
super().addError(test, err)
- self.__write('E', 'ERROR')
def addExpectedFailure(self, test, err):
self._add_result(test, True, output=self.__makeErrorDict(*err))
super().addExpectedFailure(test, err)
- self.__write('x', 'expected failure')
def addFailure(self, test, err):
self._add_result(test, True, failure=self.__makeErrorDict(*err))
super().addFailure(test, err)
- self.__write('F', 'FAIL')
def addSkip(self, test, reason):
self._add_result(test, skipped=reason)
super().addSkip(test, reason)
- self.__write('S', f'skipped {reason!r}')
def addSuccess(self, test):
self._add_result(test)
super().addSuccess(test)
- self.__write('.', 'ok')
def addUnexpectedSuccess(self, test):
self._add_result(test, outcome='UNEXPECTED_SUCCESS')
super().addUnexpectedSuccess(test)
- self.__write('u', 'unexpected success')
-
- def printErrors(self):
- if self.__verbose:
- self.stream.write('\n')
- self.printErrorList('ERROR', self.errors)
- self.printErrorList('FAIL', self.failures)
-
- def printErrorList(self, flavor, errors):
- for test, err in errors:
- self.stream.write(self.separator1)
- self.stream.write(f'{flavor}: {self.getDescription(test)}\n')
- self.stream.write(self.separator2)
- self.stream.write('%s\n' % err)
def get_xml_element(self):
if not self.USE_XML:
https://github.com/python/cpython/commit/70ccee418d1f9d34ed15cfe7104221f9cf…
commit: 70ccee418d1f9d34ed15cfe7104221f9cfd27d03
branch: main
author: Irit Katriel <1055913+iritkatriel(a)users.noreply.github.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2021-08-31T20:41:20+03:00
summary:
bpo-45039: Consistently use ADDOP_LOAD_CONST in compiler rather than ADDOP_O(c, LOAD_CONST,...) (GH-28015)
files:
M Python/compile.c
diff --git a/Python/compile.c b/Python/compile.c
index 053915e55df9a..4a4e068e2b71d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1638,12 +1638,14 @@ compiler_addop_j_noline(struct compiler *c, int opcode, basicblock *b)
}
#define ADDOP_O(C, OP, O, TYPE) { \
+ assert((OP) != LOAD_CONST); /* use ADDOP_LOAD_CONST */ \
if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) \
return 0; \
}
/* Same as ADDOP_O, but steals a reference. */
#define ADDOP_N(C, OP, O, TYPE) { \
+ assert((OP) != LOAD_CONST); /* use ADDOP_LOAD_CONST_NEW */ \
if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) { \
Py_DECREF((O)); \
return 0; \
@@ -1821,7 +1823,7 @@ compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b)
static int
compiler_call_exit_with_nones(struct compiler *c) {
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ ADDOP_LOAD_CONST(c, Py_None);
ADDOP(c, DUP_TOP);
ADDOP(c, DUP_TOP);
ADDOP_I(c, CALL_FUNCTION, 3);
@@ -5226,7 +5228,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
if(!compiler_call_exit_with_nones(c))
return 0;
ADDOP(c, GET_AWAITABLE);
- ADDOP_O(c, LOAD_CONST, Py_None, consts);
+ ADDOP_LOAD_CONST(c, Py_None);
ADDOP(c, YIELD_FROM);
ADDOP(c, POP_TOP);
https://github.com/python/cpython/commit/54f100514b02f6628450043e21ccfe3935…
commit: 54f100514b02f6628450043e21ccfe39350d7ac7
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: terryjreedy <tjreedy(a)udel.edu>
date: 2021-08-31T13:32:01-04:00
summary:
bpo-45059: Fix IDLE test typo: using "==" instead of "=" (GH-28086)
files:
M Lib/idlelib/idle_test/test_macosx.py
diff --git a/Lib/idlelib/idle_test/test_macosx.py b/Lib/idlelib/idle_test/test_macosx.py
index b6bd922e4b99dd..19324773586896 100644
--- a/Lib/idlelib/idle_test/test_macosx.py
+++ b/Lib/idlelib/idle_test/test_macosx.py
@@ -34,7 +34,7 @@ def test_init_sets_tktype(self):
for platform, types in ('darwin', alltypes), ('other', nontypes):
with self.subTest(platform=platform):
macosx.platform = platform
- macosx._tk_type == None
+ macosx._tk_type = None
macosx._init_tk_type()
self.assertIn(macosx._tk_type, types)