[Python-Dev] itertools predicates

Steven D'Aprano steve at pearwood.info
Thu Nov 3 18:51:05 EDT 2016


On Wed, Nov 02, 2016 at 07:03:27PM -0300, Francisco Couzo wrote:
> Some functions that take a predicate from itertools accept None as its
> predicate:
[...]
> I'd be interested in writing a patch to make itertools more consistent if
> there's a consensus.

There's a line in PEP 8 about foolish consistency. Consistency just for 
the sake of consistency is not a virtue.

I have no objection to adding support for None to individual itertools 
functions on the basis that it makes sense for that function. If you can 
suggest a reasonable and *useful* default predicate or key function to 
use for None, then sure, add it to the tracker as a feature enhancement. 
(And, of course, a patch would be appreciated.)

But that will be because it is a useful enhancement, not because of 
"consistency". 


> I see two possible solutions:

Before there can be a solution, there first has to be a problem that 
needs solving. "Lack of consistency" is not necessarily a problem. The 
intertools functions are quite different, they do different things with 
different APIs. The question here should not be "why don't these 
functions take None as an argument?", rather it should be "why should 
these functions take None as an argument?".



-- 
Steve


More information about the Python-Dev mailing list