from future import pass_function

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jul 26 10:36:15 CEST 2012


On Thu, 26 Jul 2012 08:39:25 +0200, Ulrich Eckhardt wrote:

> I have seen code that just created a list comprehension to iterate over
> something but was discarding the results. That could be a case for a "do
> nothing" function.

That would be a case for *not* using a list comprehension.

Using a list comp when you don't want the results is the wrong way to do 
it. That's like hammering a screw into a wall with a wrench. Okay, I 
admit it, sometimes if I'm lazy and I'm in the interactive interpreter 
and I need to consume use up results from an iterator, I type:

_ = [x for x in iterator]

and then I kick myself because I could have just written:

_ = list(iterator)

but in actual code, I'm not so lazy to bang that screw into the wall 
using a wrench. I at least reach for a hammer:

_ = [None for x in iterator]

or better still, a drill:

collections.deque(iterator, maxlen=0)



But fine, you need a do-nothing function. Here you go:

_ = [(lambda x: None)(x) for x in sequence]


> Just having a function that does nothing would be useful in other
> places, too. In some cases, you want to print() some debug output in
> other cases you just use pass() to discard the debug output.

You're still not giving reasons why *pass* should be a do-nothing 
function. Of course there are good use-cases for do-nothing functions, 
that goes without saying. But you have to explain why:

1) that do-nothing function is so common and so important that it has to 
be a built-in function; and

2) why it needs to be called "pass".


Nobody is disputing the usefulness of do nothing functions. We're 
disputing that *pass* should be that function.



-- 
Steven



More information about the Python-list mailing list