Fix traceback reporting for exceptions with __cause__ cycles.#3805
Fix traceback reporting for exceptions with __cause__ cycles.#3805RonnyPfannschmidt merged 1 commit intopytest-dev:masterfrom asottile:cause_cycles
__cause__ cycles.#3805Conversation
testing/code/test_excinfo.py
Outdated
| assert ( | ||
| out | ||
| == """\ | ||
| :13: in unreraise |
There was a problem hiding this comment.
Ouch this formatting here is messy IMHO. How about this instead:
out = "\n".join(line for line in tw.lines if isinstance(line, str))
expected_out = textwrap.dedent(
"""\
:13: in unreraise
reraise()
:10: in reraise
raise Err() from e
E test_exc_chain_repr_cycle0.mod.Err
During handling of the above exception, another exception occurred:
:15: in unreraise
raise e.__cause__
:8: in reraise
fail()
:5: in fail
return 0 / 0
E ZeroDivisionError: division by zero"""
)
assert out == expected_outWhat do you think?
Otherwise the rest of the patch looks good, thanks!
There was a problem hiding this comment.
ugh, I didn't even notice, black made this look way worse :(
| descr = None | ||
| while e is not None: | ||
| seen = set() | ||
| while e is not None and id(e) not in seen: |
There was a problem hiding this comment.
i believe for exceptions its fine to use the direct object banking on the object identity hashing by default,
and that way this wouldn't incur the same cost as it does with id() on pypy
There was a problem hiding this comment.
I didn't really want to make assumptions about exceptions since any user space exception could appear here, even one with an exceptionally bad __hash__ + __eq__. I considered using object.__hash__(e) instead of id(e) but I figure they're probably the same.
The "performance hit" in pypy is almost certainly negligible and this isn't a performance critical path (formatting failed test tracebacks).
There was a problem hiding this comment.
thanks for the rebuttal
Resolves #3804