[Python-ideas] Allow filter(items)

Andrew Barnert abarnert at yahoo.com
Wed Aug 7 22:54:19 CEST 2013


On Aug 7, 2013, at 10:31, Terry Reedy <tjreedy at udel.edu> wrote:

> On 8/7/2013 6:01 AM, Alexander Belopolsky wrote:
> 
>> From Guido's time machine comes a pronouncement:
> <http://bugs.python.org/issue2186#msg63026>.
> 
> As Raymond points out in a later message, it is standard in Python for None passed to a function to mean 'no argument, do something that does not require an value for this parameter'. It does not mean 'use a value of None for this parameter and do with None whatever would be done with any other value'.
> 
> Usually, only trailing parameters are allowed to be given None and then it is given in the definition as a default.
>  def f(a, b=None, c=None): pass
> can be called f(x), f(x, y), f(x, y, z), and f(x, None, z) or f(x, c=z). Because of the last option, there is never a need for the user to explicitly pass None.
> 
> What is unusual about filter is not the use of None to mean 'no argument, behave differently', but the need for it to be written explicitly by the caller to get the null behavior. 

There are other functions like that. For example, to set a max split, but still get the default behavior of splitting on any whitespace instead of a specific character, you have to write s.split(None, 2).

I'm not suggesting that it's an ideal design, just that it's not uniquely special to filter.


More information about the Python-ideas mailing list