[issue19022] Improve handling of type.__abstractmethods__ descriptor
Nick Coghlan
report at bugs.python.org
Sun Sep 15 09:33:28 CEST 2013
New submission from Nick Coghlan:
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
----------
messages: 197755
nosy: ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Improve handling of type.__abstractmethods__ descriptor
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19022>
_______________________________________
More information about the Python-bugs-list
mailing list