To be conform to Python doc and standard, __getattr__ has to raise an AttributeError if attribute is not there and not a KeyError. Example of test in Python 2.7:
>>> class Foo: pass
>>> Foo().test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute 'test'
I have tested too in Python 2.5, the older Python distrib than Inline Python talks about in the documentation.
To give you a little context, I'm currently finishing to port Inline Python to Python 3. In P3, __getattr__ MUST raise AttributeError if the attribute does not exist, otherwise our "getattr" implementation is not correct (i.e. hasattr raises an exception, do not answer False) . Since it's even the standard in Python 2.x, I think it's interesting to correct it directly in Inline Python core, without a "if py_version == 3" condition.
In the next days, I will try to make more pull requests of things indirectly linked to the Python 3 port. My main goal is to make the more atomic commits that I can. I think it's a good practice and in addition easier for you to check.
Hi,
To be conform to Python doc and standard,
__getattr__
has to raise anAttributeError
if attribute is not there and not aKeyError
. Example of test in Python 2.7:I have tested too in Python 2.5, the older Python distrib than Inline Python talks about in the documentation.
To give you a little context, I'm currently finishing to port Inline Python to Python 3. In P3,
__getattr__
MUST raiseAttributeError
if the attribute does not exist, otherwise our "getattr" implementation is not correct (i.e.hasattr
raises an exception, do not answerFalse
) . Since it's even the standard in Python 2.x, I think it's interesting to correct it directly in Inline Python core, without a "if py_version == 3" condition.In the next days, I will try to make more pull requests of things indirectly linked to the Python 3 port. My main goal is to make the more atomic commits that I can. I think it's a good practice and in addition easier for you to check.
Hope it helps!