optional pass? (was Re: Dr. Dobb's Python-URL! - weekly Python news and links (Mar 26))

Dave Brueck dave at pythonapocrypha.com
Fri Mar 29 12:59:16 EST 2002


philh at comuno.freeserve.co.uk (phil hunt) wrote in message news:<slrnaa6sfc.d02.philh at comuno.freeserve.co.uk>...
> On Thu, 28 Mar 2002 19:09:13 +0100, Stefan Schwarzer <s.schwarzer at ndh.net> wrote:
> >What about
> >
> >class BaseClass: pass
> >
> >class MyClass(BaseClass):
> >   def __init__(self): pass
> >   def method1(self, a, b, c): pass
> >   def method2(self, d, e): pass
> >   def method3(self, f): pass
> >
> >IMHO, that looks almost as well as your version, and makes the absence
> >of additional code seem rather intentional, not accidental.
> 
> True, but i still have to remove the passes when i want to implement 
> the class.

No you don't. They're no-ops. If you are prioritizing on reducing
keystrokes, then you should leave them in there. If you are
prioritizing on clean, readable code, then you'll happily put them in
there (or perhaps better, raise an exception) and happily take them
out later.

Perhaps a change in perspective would help you: the with-pass versions
of functions are not "unimplemented" but "minimally implemented". Your
proposal is to make unimplemented code parsable and runnable, which
makes no sense. It's like saying that, until you're ready to flesh out
the code, you also want to omit the colon and parentheses on the 'def'
line but you want Python to not complain about this.

If this is really driving you crazy, add a couple of macros to your
editor - no point in changing the language over something so trivial.

-Dave



More information about the Python-list mailing list