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 ncoghlan
Recipients ncoghlan
Date 2013-09-15.07:33:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379230408.43.0.525404043988.issue19022@psf.upfronthosting.co.za>
In-reply-to
Content
Issue 10006 pointed out that attempting to access object.__abstractmethods__ raises AttributeError. The solution was to ensure type.__abstractmethods__ *also* raises AttributeError.

This is thoroughly confusing, since the name is clearly visible in the output of dir(type). While it's technically legal for a descriptor to always raise AttributeError, breaking the following typical assumed invariant is *highly* dubious:

    all(hasattr(obj, x) for x in dir(obj))

I see three main alternatives for improving the situation:

1. Make __abstractmethods__ a read-only descriptor that returns something meaningful (like a frozenset(), the same as you get if you inherit from abc.ABCMeta without defining any abstract methods)

2. Throw a better exception message that explains the broken invariant rather than the generic "AttributeError with attribute name" that is currently thrown.

3. Implement type.__dir__ to filter out the uncooperative descriptor
History
Date User Action Args
2013-09-15 07:33:28ncoghlansetrecipients: + ncoghlan
2013-09-15 07:33:28ncoghlansetmessageid: <1379230408.43.0.525404043988.issue19022@psf.upfronthosting.co.za>
2013-09-15 07:33:28ncoghlanlinkissue19022 messages
2013-09-15 07:33:27ncoghlancreate