[issue20897] @abstractmethod does not enforce method signatures

the mulhern report at bugs.python.org
Tue Mar 18 14:44:43 CET 2014


the mulhern added the comment:

I feel that I worded this in a way that makes it look like I'm asking for an enhancement, not reporting a bug, so I'll try again.

The documentation for 2.7.6 and 3.4.0 says:

Using this decorator requires that the class’s metaclass is ABCMeta or is derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods and properties are overridden. The abstract methods can be called using any of the normal ‘super’ call mechanisms.

The second sentence is a little obscure, but what it must mean is that a class that has a metaclass derived from ABCMeta or a class that extends such a class cannot be instantiated unless all of its abstract method and properties are overridden.

Now, in this example, both Sub and SuperSubber have an abstract method _junk(self) and neither of them overrides this method. Therefore, neither should be instantiated.

But they can both be instantiated in 3.3 and one can be instantiated in 2.7.

So, the behavior does seem to me to disagree with the documentation.

In fact, in Python 3.3.2 I can instantiate the META class in the example, which seems really wrong. I can not instantiate the META class in 2.7.6.

----------
type: enhancement -> behavior

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


More information about the Python-bugs-list mailing list