This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Yaroslav.Halchenko
Recipients Yaroslav.Halchenko
Date 2010-10-01.13:47:30
SpamBayes Score 7.40761e-08
Marked as misclassified No
Message-id <1285940853.14.0.546762707016.issue10006@psf.upfronthosting.co.za>
In-reply-to
Content
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())? ;)
History
Date User Action Args
2010-10-01 13:47:33Yaroslav.Halchenkosetrecipients: + Yaroslav.Halchenko
2010-10-01 13:47:33Yaroslav.Halchenkosetmessageid: <1285940853.14.0.546762707016.issue10006@psf.upfronthosting.co.za>
2010-10-01 13:47:31Yaroslav.Halchenkolinkissue10006 messages
2010-10-01 13:47:30Yaroslav.Halchenkocreate