What exactly is "pass"? What should it be?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Nov 18 01:07:21 EST 2011


On Thu, 17 Nov 2011 21:07:23 -0800, John Ladasky wrote:

> One of my questions was: would there be any merit to having the Python
> "pass" token itself defined exactly as _pass() is defined above?

No.

The pass statement compiles to nothing at all. Your _pass() function 
compiles to a function object, which needs to be looked up at run time, 
then called, all of which takes time and memory.

To satisfy the compiler, but do nothing, the pass statement should stay a 
statement. When you need a "do nothing" function, either define one (two 
lines) in your application, or use a lambda in place (lambda *args: 
None). Either way, it is too trivial to be a built-in.

By the way, to answer your earlier question "what is pass?", you could do 
this in the interactive interpreter:

help("pass")




-- 
Steven



More information about the Python-list mailing list