from future import pass_function

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jul 25 07:33:26 EDT 2012


On Wed, 25 Jul 2012 10:40:45 +0200, Ulrich Eckhardt wrote:

> Hi!
> 
> I just had an idea, it occurred to me that the pass statement is pretty
> similar to the print statement, 
[...]
>     try:
>         do_something()
>     except:
>         pass()

What's the point of this? If you intend to do nothing, why call a 
function instead?

There's a surprising amount of effort involved behind the scenes in 
calling a function. Python has to:

1) look up the function's name to get access to the function object
2) push any arguments onto the stack
3) determine the function object's type
4) look up its __call__ method
5) match the arguments (if any) with the parameter list (if any)
6) execute the function body
7) push the return result (None) onto the stack in case it's needed
8) and pop it off the stack.

Turning pass into a function instead of a statement would essentially 
take something that does *nothing at all* into something that 
(figuratively speaking) jumps up to its feet, runs around the room three 
times, and then sits back down again.


-- 
Steven



More information about the Python-list mailing list