pre-PEP for optional 'pass'
phil hunt
philh at comuno.freeserve.co.uk
Mon Apr 15 19:26:10 EDT 2002
OK, I've decided to write a PEP. Preliminary to this, I'd like
people's comments.
I wish to make the pas startement optional. That is, in any Python
program where there is a pass it can be left out and the meaning of
the program is unchanged.
There are two rationales for this: convenience and beauty.
(1) Convenience
I would like to be able to write as code classes and functions
without implementing the body to start with, e.g.:
class MyClass:
def __init__(self, x, ,y, z):
def getTwiddle(self):
def setTwiddle(self, twiddle):
At the moment if I want to do this I have to put pass in and then
take them out again. A minor inconvenience, to be sure, but one that
niggles slightly due to the highly exploratory style of coding I
often use.
(2) Beauty
In my opinion this change is Pythonic.
Consider the following code:
if condition:
statement1()
statement2()
statement3()
else:
statement4()
statement5()
statement6()
If I remove the statement1() line, the program will still execute,
and will behave as before except that staement1() is not executed.
This is true if I then remeove the statement2() line. So the rule
appears to be: if you have a block of n statements, you can remove
one of them and the program behaves as before except not executing
the one removed.
But if I then remove statement3() it is suddenly a syntax error.
So blocks 1 statement long currently behave differently to blocks >1
statement long. I propose that this irregularity be removed.
In python, you can say:
x = [ ]
specifying an empty list in the obvious way. You don't have to say
x = [ empty ]
or:
x = [ pass ]
or anything like that. I propose to bring groups of staements in
line with that principle.
Thoughts?
--
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically
advantageous for him to believe."
-- Alison Brooks, referring to Michael
Portillo, on soc.history.what-if
More information about the Python-list
mailing list