[issue9212] dict_keys purports to implement the Set ABC, but is missing the isdisjoint method

Daniel Stutzbach report at bugs.python.org
Sun Jul 11 01:42:25 CEST 2010


Daniel Stutzbach <daniel at stutzbachenterprises.com> added the comment:

In this case, the concrete class is the one missing a method.  

Concrete classes are allowed to provide more features than the corresponding ABC, but the converse is not true to the best of my knowledge.

dict_keys .register()s as supporting the Set ABC, so it does not automatically pick up the method through inheritance.  Put another way:

>>> # dict_keys provides the Set ABC API
>>> isinstance({}.keys(), collections.Set)
True

>>> # The Set ABC provides isdisjoint
>>> hasattr(collections.Set, 'isdisjoint') 
True

>>> # Ergo, dict_keys should provide isdisjoint ... but it doesn't
>>> hasattr({}.keys(), 'isdisjoint')       
False

See also Issue9213 for another case where a concrete class is missing a method provided by an ABC it claims to support.

I sort of wonder if .register() should verify that the concrete class provides all of the methods of the ABC.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9212>
_______________________________________


More information about the Python-bugs-list mailing list