[issue17413] format_exception() breaks on exception tuples from trace function
Roundup Robot added the comment: New changeset d18df4c90515 by R David Murray in branch '3.3': #17413: make sure settrace funcs get passed exception instances for 'value'. http://hg.python.org/cpython/rev/d18df4c90515 New changeset 6297fcddf912 by R David Murray in branch 'default': Merge #17413: make sure settrace funcs get passed exception instances for 'value'. http://hg.python.org/cpython/rev/6297fcddf912 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
R. David Murray added the comment: Benjamin reviewed the patch and pointed out that the settrace state needed to be restored in the test, so I fixed that when I committed it. Thanks Ingrid and Brendan. -- resolution: - fixed stage: commit review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
ingrid added the comment: Thank you, r.david.murray. I have updated the patch with your suggestions included. -- Added file: http://bugs.python.org/file29917/issue17413.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
R. David Murray added the comment: Thanks Ingrid and Mark. The patch looks good; I put a couple of FYI comments on the review. I'm pretty sure this patch is correct, but I'd like someone with more experience modifying the ceval loop to confirm, so I'm nosying Benjamin. -- nosy: +benjamin.peterson stage: needs patch - commit review versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
ingrid added the comment: It seems that settrace works normally when an exception is raised in the python code with the raise keyword. If an exception is raised in the C code, settrace breaks as the C code passes all exceptions as strings. To fix this issue we just added a line to normalize the C exception within settrace. We included a regression test for this defect. I paired on this with user bmac (http://bugs.python.org/user17692). -- keywords: +patch nosy: +ingrid Added file: http://bugs.python.org/file29837/issue17413.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
Changes by ingrid h...@ingridcheung.com: -- nosy: +bmac ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
Helmut Jarausch added the comment: The problem is caused by the new format_exception in Python's traceback.py file. It reads def format_exception(etype, value, tb, limit=None, chain=True): list = [] if chain: values = _iter_chain(value, tb) else: values = [(value, tb)] for value, tb in values: if isinstance(value, str): and then def _iter_chain(exc, custom_tb=None, seen=None): if seen is None: seen = set() seen.add(exc) its = [] context = exc.__context__ As you can see, the new keyword parameter chain is True by default. Thus, iter_chain is called by default. And there you have context= exc.__context__. Now, if value is an object of type str Python tries to access the __context__ field of an object of type str. And this raises an attribute error. In an application (pudb) I've used the fixed exc_info= sys.exc_info() format_exception(*exc_info,chain=not isinstance(exc_info[1],str)) So, why is the keyword parameter 'chain' True by default. This causes the problem. -- nosy: +HJarausch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
R. David Murray added the comment: Because the second argument to format_traceback is supposed to be (is documented to be) an exception object. The fact that it used to work anyway in Python2 if you passed a string was an accident of the implementation. Likewise, settrace is documented to provide a value, not a string, so the fact that it provides a string is a bug. That needs to be fixed. (As to specifically why chain defaults to True, it defaults to having the same behavior as the normal exception machinery.) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
Andreas Kloeckner added the comment: Thanks for the suggestion. Since 3.2 and 3.3 will be with us for a while, I've implemented the workaround you've suggested. Works, too. :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
R. David Murray added the comment: It looks like a bug in the tracing machinery that has only been revealed by the changes to how tracebacks are interpreted in python3. It should be a relatively simple fix, but I wonder if there is existing code that depends on the second argument getting turned into a string. You can hack around the problem by creating a class to wrap around the arg[1] you get that has __cause__ and __context__ attributes, both set to none, and whose __str__ returns the original string. -- keywords: +easy nosy: +r.david.murray stage: - needs patch title: format_exception() breask on exception tuples from trace function - format_exception() breaks on exception tuples from trace function versions: +Python 3.2, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17413] format_exception() breaks on exception tuples from trace function
Changes by Aaron Meurer asmeu...@gmail.com: -- nosy: +Aaron.Meurer ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com