[issue31213] __context__ reset to None in nested exception

2021-04-19 Thread Irit Katriel


Change by Irit Katriel :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31213] __context__ reset to None in nested exception

2021-01-08 Thread Irit Katriel


Irit Katriel  added the comment:

This seems to be deliberately done here in order to prevent context cycles from 
forming: 
https://github.com/python/cpython/blob/fe6e5e7cfd68eeaa69fd1511f354a1b4d8d90990/Python/errors.c#L148

In your code you are creating a cycle where foo is the context (and cause) for 
bar which is the context (and cause) of the second time foo is raised. 

If you create a new instance of foo for the second raise then there is no cycle 
and you get what you expect:

try:
try:
raise Exception('foo')
except Exception as foo:
print("1--", foo, foo.__context__, foo.__cause__)
try:
raise Exception('bar') from foo
except Exception as bar:
print("2--", bar, bar.__context__, bar.__context__.__context__)
raise Exception('foo2') from bar
except Exception as foo:
wat = foo

print("3--", wat, wat.__context__, wat.__context__.__context__)
print("4--", wat, wat.__cause__, wat.__cause__.__context__)
print("5--", wat, wat.__cause__, wat.__cause__.__cause__)


Output is:

1-- foo None None
2-- bar foo None
3-- foo2 bar foo
4-- foo2 bar foo
5-- foo2 bar foo


I think the bug is in your code - you can't create an exception chain that 
contains the same exception instance more than once.

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31213] __context__ reset to None in nested exception

2020-06-06 Thread Chris Jerdonek


Change by Chris Jerdonek :


--
nosy: +chris.jerdonek

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31213] __context__ reset to None in nested exception

2017-08-15 Thread Christopher Stelma

Christopher Stelma added the comment:

crosslink to related future lib issue that led me to this:

https://github.com/PythonCharmers/python-future/issues/141

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31213] __context__ reset to None in nested exception

2017-08-15 Thread Christopher Stelma

New submission from Christopher Stelma:

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.

e.g.

>>> 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.

--
messages: 300305
nosy: Christopher Stelma
priority: normal
severity: normal
status: open
title: __context__ reset to None in nested exception
type: behavior
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com