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 <rep...@bugs.python.org>
<http://bugs.python.org/issue19022>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to