New submission from Yaroslav Halchenko <yarikop...@gmail.com>:

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.:
http://bitbucket.org/DasIch/bpython-colorful/src/19bb4cb0a65d/bpython/repl.py
when __abstractmethods__ is accessed only for the subclasses of ABCmeta ...

so, is it a bug or a feature (so we have to take care about it in all 
traversals of attributes given by dir())? ;)

----------
messages: 117798
nosy: Yaroslav.Halchenko
priority: normal
severity: normal
status: open
title: non-Pythonic fate of __abstractmethods__
versions: Python 2.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10006>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to