Author Christopher Stelma
Recipients Christopher Stelma
Date 2017-08-15.17:43:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
When I try to re-raise an exception with a __cause__ inside a nested exception, the __context__ of the outer __context__ appears to be reset to None.


>>> try:
...     try:
...         raise Exception('foo')
...     except Exception as foo:
...         print(foo, foo.__context__, foo.__cause__)
...         try:
...             raise Exception('bar') from foo
...         except Exception as bar:
...             print(bar, bar.__context__, bar.__context__.__context__)
...             raise foo from bar
... except Exception as foo:
...     wat = foo
foo None None
bar foo None
>>> print(wat, wat.__context__, wat.__context__.__context__)
foo bar None
>>> print(wat, wat.__cause__, wat.__cause__.__context__)
foo bar None
>>> print(wat, wat.__cause__, wat.__cause__.__cause__)
foo bar foo

here, between "raise foo from bar" and the end, bar.__context__ goes from foo to None.  since bar is only raised once, clearly in the context of foo (twice over), I would expect bar.__context__ to stay foo.
Date User Action Args
2017-08-15 17:43:59Christopher Stelmasetrecipients: + Christopher Stelma
2017-08-15 17:43:59Christopher Stelmasetmessageid: <>
2017-08-15 17:43:59Christopher Stelmalinkissue31213 messages
2017-08-15 17:43:59Christopher Stelmacreate