Is there a technical reason why pass
must be used
to express "no action" in python, rather than letting
absence-of-a-statement signify it?
According to the python3.8 doc:
The
pass
statement does nothing. It can be used when a statement is required syntactically but the program requires no action".
This is followed by the following three examples:
while True:
pass # Busy-wait for keyboard interrupt (Ctrl+C)
class MyEmptyClass:
pass
def initlog(*args):
pass # Remember to implement this!
It looks to me like all these uses of pass
are driven by
the fact that each of the keywords while
, if
, class
, def
, etc.
require one-or-more following indented statements.
So, if the language were relaxed so that each of those keywords could be
followed by zero-or-more statements, then it seems that pass
wouldn't be necessary.
If that were done, then the above examples could be written as:
while True:
# Busy-wait for keyboard interrupt (Ctrl+C)
class MyEmptyClass:
def initlog(*args):
# Remember to implement this!
Is there any technical reason why this wouldn't work?
What I'm asking for is either:
an example where allowing absence-of-a-statement instead of
pass
would introduce a parsing ambiguity, or other concrete parsing difficulty (such as the language no longer being LL(1), if it was before) Or,a convincing argument showing that changing python's grammar in this way would not introduce any such difficulty.
Commentary on closure
I don't think this is an opinion question; I am neither offering nor soliciting opinions on whether pass
is more or less natural, simple, readable, convenient, or error-resistant than absence-of-a-statement would be.
In particular, an answer or comment that includes the words "explicit is better than implicit" is not what I am ideally seeking.
I don't believe this is a duplicate of "How to use the pass statement" since it is not answered by any of the answers currently attached to that question.