New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
non-Pythonic fate of __abstractmethods__ #54215
Comments
We ran into this while generating documentation for our project (PyMVPA) with recent sphinx and python2.6 (fine with 2.5, failed for 2.6, 2.7, 3.1), which relies on traversing all attributes given by "dir(obj)", BUT apparently __abstractmethods__ becomes very special -- it is given by "dir(obj)" since it is present in obj.__class__, but getattr(obj, "__abstractmethods__") fails for classes derived from type. E.g. following sample demonstrates it: print("in type's dir" , '__abstractmethods__' in dir(type))
print(type.__abstractmethods__)
class type3(type):
pass
print("in type3's dir" , '__abstractmethods__' in dir(type3))
print(type3.__abstractmethods__) results in output: $> python2.6 trash/type_subclass.py
("in type's dir", True)
<attribute '__abstractmethods__' of 'type' objects>
("in type3's dir", True)
Traceback (most recent call last):
File "trash/type_subclass.py", line 9, in <module>
print(type3.__abstractmethods__)
AttributeError: __abstractmethods__
$> python3.1 trash/type_subclass.py
in type's dir True
<attribute '__abstractmethods__' of 'type' objects>
in type3's dir True
Traceback (most recent call last):
File "trash/type_subclass.py", line 9, in <module>
print(type3.__abstractmethods__)
AttributeError: __abstractmethods__ And that seems to be the only attribute behaving like that (others are fine and accessible). Some people even seems to provide workarounds already, e.g.: so, is it a bug or a feature (so we have to take care about it in all traversals of attributes given by dir())? ;) |
I see the problem; will consider/fix later today hopefully. |
As of r85154, type.__abstractmethods__ now raises an AttributeError, too. |
yikes... surprising resolution -- I expected that fix would either makes __abstractmethods__ accessible in derived "type"s or becomes absent from output of dir() -- but none of those has happened. Now we ended up with a consistent non-Pythonic fate of __abstractmethods__ listed in output of dir() but not accessible. is that a feature? |
2010/10/1 Yaroslav Halchenko <report@bugs.python.org>:
type has no __abstractmethods__, so it should raise an AttributeError. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: