[Python-ideas] The prohibition overrides the class method

Joseph Jevnik joejev at gmail.com
Mon Nov 16 14:19:28 EST 2015


def finalmethod(f):
    f.__doc__ += 'DO NOT OVERRIDE THIS METHOD. IF YOU OVERRIDE THIS METHOD,
YOU WILL DIE!'
    return f

On Mon, Nov 16, 2015 at 1:24 PM, Ryan Gonzalez <rymg19 at gmail.com> wrote:

> You could always put this in the docstring:
>
> DO NOT OVERRIDE THIS METHOD. IF YOU OVERRIDE THIS METHOD, YOU WILL DIE.
>
>
> Short, the-the-point, and evokes fear.
>
> ...
>
> Seriously, though, I personally think this might go well with the whole
> PEP 484 type-annotation thing. I mean, if there are already generics and
> abstract methods. If we're going for static typing, adding final would fit
> well. Something like:
>
> @finalmethod
> def whatever(self): ...
>
> The type checker (in this case, Mypy) would check it, but there would be
> no runtime effect.
>
> On November 16, 2015 12:15:55 PM CST, "Иван Спиненко" <
> spinenkoia at gmail.com> wrote:
>>
>> Thank you for the constructive responses, perhaps, I agree with you that
>> this is not in the spirit of Python.
>> As for the real example of the use, sometimes there to make the
>> implementation of the method in the base class, but that none of the rest
>> of the development team could not accidentally or unknowingly override this
>> method (perhaps due to the need to be unsuccessful architecture).
>>
>> ------------------------------
>>
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>>
> --
> Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151116/f0b7ef72/attachment.html>


More information about the Python-ideas mailing list