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

Stefan Schwarzer s.schwarzer at ndh.net
Thu Mar 28 13:09:13 EST 2002


phil hunt wrote:
> And Guido's statement supports my suggestion that pass be made 
> optional in Python. Consider, when someone is designing a class, 
> one could write an outline like this:
> 
> class BaseClass:
> 
> class MyClass(BaseClass):
>    def __init__(self):
>    def method1(self, a, b, c):
>    def method2(self, d, e):
>    def method3(self, f):
> 
> It is perfectly clear what this means.

I know that there may be reasons to write such code. What I like
about pass is that it reminds me to make it explicit if I omit an
implementation of e. g. a method.

> But unfortunately, as Python
> stands today, it is syntactically invalid, one would have to say:
> 
> 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

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.

If I remember correctly, I seldom use that many pass's, so I don't
bother whether I have to write them.

> And then, when you begin to flesh out your code, you would have to
> get rid of the extraneous passes you didn't want to add (assuming
> you are like me) in the first place. So the with-pass version
> requires more effort, and is more verbose, for no good reason.

I value the explicitness of pass over having to write or delete a bit
less.

Stefan



More information about the Python-list mailing list