[issue20897] @abstractmethod does not enforce method signatures
the mulhern
report at bugs.python.org
Wed Mar 12 13:49:16 CET 2014
New submission from the mulhern:
Hi!
Here is a simple class hierarchy:
>>> import abc
>>> class META(object):
... __metaclass__ = abc.ABCMeta
... @abc.abstractmethod
... def _junk(self):
... pass
...
>>> class Sub(META):
... def _junk(self, other):
... pass
...
>>> class Subber(META):
... def _junk(self):
... pass
...
>>> class SuperSubber(META):
... pass
...
In 2.7.5 I can instantiate an object of Sub or Subber, although Sub does not really override META's abstract method.
I think it would be better if I could not instantiate Sub, because the signature of the abstract method in META
is different from the signature of the overriding method in Sub.
I can not instantiate SuperSubber, I get a TypeError. That seems correct.
In 3.3.2 I can instantiate all three, Sub, Subber, and SuperSubber.
I would prefer to only be able to instantiate Subber, since it is the only class that truly overrides the abstract method
_junk in META.
- mulhern
----------
components: Library (Lib)
messages: 213256
nosy: the.mulhern
priority: normal
severity: normal
status: open
title: @abstractmethod does not enforce method signatures
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20897>
_______________________________________
More information about the Python-bugs-list
mailing list