[Python-ideas] Decorator to avoid a mistake

Chris Barker chris.barker at noaa.gov
Mon Nov 28 13:11:12 EST 2016


Am I missing something?

Given Python's dynamic nature, there is simply no way to know if a method
is overriding a superclass' method until it is called -- and, now that I
think about it even then you don't know.

At compile time, none of the superclasses may have the given method.

At run time, a method could be monkey patched into the superclass before
the subclass' instance is created.

In fact, at run time, the superclass could get the method added after
instances are created.

At calling time, the subclass' method will be found, and used, and the
search stops there -- no way to know if there is one with the same name
further up the MRO.

This is simply incompatable with a language this dynamic.

On Fri, Nov 25, 2016 at 7:26 PM, Guido van Rossum <guido at python.org> wrote:

> Here it's brought up from time to time and the response is usually "let a
> linter do it".
>

Exactly -- it can't be enforced, but maybe it's nice for a linter to give
some information at develop time.

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161128/4889ebcd/attachment.html>


More information about the Python-ideas mailing list