[Python-ideas] The prohibition overrides the class method
Иван Спиненко
spinenkoia at gmail.com
Mon Nov 16 10:03:32 EST 2015
Hello, I want to apologize for my English.
I propose to make an analogue of the final specifier in C ++. In class
abc.ABCMeta has decorator abstractmethod, you can add decorator finalmethod.
I have a sketch of implementation:
def finalmethod(funcobj):
funcobj.__isfinalmethod__ = True
return funcobj
class Override(ABCMeta):
def __init__(cls, name, bases, namespace):
super(Override, cls).__init__(name, bases, namespace)
finals = {name
for name, value in namespace.items()
if getattr(value, "__isfinalmethod__", False)
}
for base in bases:
for name in getattr(base, "__finalmethods__", set()):
value = getattr(cls, name, None)
if getattr(value, "__isfinalmethod__", False):
finals.add(name)
else:
raise TypeError("function '" + str(value.__name__) + "'
in class '" + str(cls.__name__) + "' is final")
cls.__finalmethods__ = frozenset(finals)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151116/dde95697/attachment.html>
More information about the Python-ideas
mailing list