You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure if this is a bug or a feature. When the input is an object attr, IPython seems to evaluate it twice. An exception thrown in the first evaluation is silently ignored. Here's an simple example:
# test.py
class DescriptorWithException(object):
def __get__(self, instance, owner_class):
if instance is None:
return self
print('accessing the descriptor')
if not hasattr(instance, 'once'):
instance.once = True
raise RuntimeError('This will be ignored by IPython')
return 0
class IPythonCatchException(object):
data = DescriptorWithException()
If we access the attr "data" in python, we get an exception:
$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> x = test.IPythonCatchException()
>>> x.data
accessing the descriptor
Traceback (most recent call last):
File "", line 1, in
File "test.py", line 8, in __get__
raise RuntimeError('This will be ignored by IPython')
RuntimeError: This will be ignored by IPython
However, if we do the same in ipython, we get no exceptions, and the attr is actually accessed twice.
$ ipython
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
Type "copyright", "credits" or "license" for more information.
IPython 0.10.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import test
In [2]: x = test.IPythonCatchException()
In [3]: x.data
accessing the descriptor
accessing the descriptor
Out[3]: 0
Interestingly, an alternative way triggers the exception:
In [4]: x = test.IPythonCatchException()
In [5]: a = x.data
accessing the descriptor
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
~/ in ()
~/test.pyc in __get__(self, instance, owner_class)
6 if not hasattr(instance, 'once'):
7 instance.once = True
----> 8 raise RuntimeError('This will be ignored by IPython')
9 return 0
10
RuntimeError: This will be ignored by IPython
The text was updated successfully, but these errors were encountered:
I am not sure if this is a bug or a feature. When the input is an object attr, IPython seems to evaluate it twice. An exception thrown in the first evaluation is silently ignored. Here's an simple example:
If we access the attr "data" in python, we get an exception:
However, if we do the same in ipython, we get no exceptions, and the attr is actually accessed twice.
Interestingly, an alternative way triggers the exception:
The text was updated successfully, but these errors were encountered: