Author: Matti Picus <[email protected]> Branch: winconsoleio Changeset: r97522:90f3fa6eca04 Date: 2019-09-18 14:41 +0300 http://bitbucket.org/pypy/pypy/changeset/90f3fa6eca04/
Log: merge py3.6 into branch diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py --- a/pypy/interpreter/argument.py +++ b/pypy/interpreter/argument.py @@ -9,7 +9,7 @@ from pypy.interpreter.error import OperationError, oefmt [email protected](1) [email protected](2) def raise_type_error(space, fnname_parens, msg, *args): if fnname_parens is None: raise oefmt(space.w_TypeError, msg, *args) diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py --- a/pypy/module/sys/app.py +++ b/pypy/module/sys/app.py @@ -22,7 +22,17 @@ try: from traceback import print_exception - print_exception(exctype, value, traceback) + limit = getattr(sys, 'tracebacklimit', None) + if isinstance(limit, int): + # ok, this is bizarre, but, the meaning of sys.tracebacklimit is + # understood differently in the traceback module than in + # PyTraceBack_Print in CPython, see + # https://bugs.python.org/issue38197 + # one is counting from the top, the other from the bottom of the + # stack. so reverse polarity here + print_exception(exctype, value, traceback, limit=-limit) + else: + print_exception(exctype, value, traceback) except: if not excepthook_failsafe(exctype, value): raise diff --git a/pypy/module/sys/interp_encoding.py b/pypy/module/sys/interp_encoding.py --- a/pypy/module/sys/interp_encoding.py +++ b/pypy/module/sys/interp_encoding.py @@ -9,16 +9,20 @@ if sys.platform == "win32": base_encoding = "mbcs" + base_error = "strict" elif sys.platform == "darwin": base_encoding = "utf-8" + base_error = "surrogateescape" elif sys.platform == "linux2": base_encoding = "ascii" + base_error = "surrogateescape" else: # In CPython, the default base encoding is NULL. This is paired with a # comment that says "If non-NULL, this is different than the default # encoding for strings". Therefore, the default filesystem encoding is the # default encoding for strings, which is ASCII. base_encoding = "ascii" + base_error = "surrogateescape" def _getfilesystemencoding(space): encoding = base_encoding @@ -51,6 +55,4 @@ def getfilesystemencodeerrors(space): - if sys.platform == "win32": - return space.newtext('strict') - return space.newtext('surrogateescape') + return space.newtext(base_error) diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py --- a/pypy/module/sys/test/test_sysmodule.py +++ b/pypy/module/sys/test/test_sysmodule.py @@ -381,6 +381,36 @@ assert out.getvalue() == 'hello\n123 456' # no final \n added in 3.x """ + def test_tracebacklimit_excepthook(self): + import sys, _io + savestderr = sys.stderr + err = _io.StringIO() + sys.stderr = err + assert not hasattr(sys, "tracebacklimit") + sys.tracebacklimit = 2 + + eh = sys.__excepthook__ + def f1(): + f2() + def f2(): + f3() + def f3(): + raise ValueError(42) + + + try: + f1() + except ValueError as exc: + eh(*sys.exc_info()) + msg = err.getvalue() + print(msg) + # should be removed by the limit + assert "f1" not in msg + + sys.stderr = savestderr + del sys.tracebacklimit + + # FIXME: testing the code for a lost or replaced excepthook in # Python/pythonrun.c::PyErr_PrintEx() is tricky. _______________________________________________ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
