[issue1673203] add identity function

Alexander Belopolsky report at bugs.python.org
Tue Feb 26 14:45:22 CET 2008


Alexander Belopolsky added the comment:

Raymond Hettinger wrote in msg63027 (issue2186):

"""
.. it looks like there [is an] agreement on dropping None for map() and 
going forward with the operator.identity() patch.  Will check these in 
in the next couple of days.
"""

This leaves open the issue of multi-argument identity.  I would argue 
that def identity(*args): return args[-1] # or args[0] will conflict 
with the use of identity instead of None in map: map(identity, x, y, ..) 
will silently produce results different from current map(None, x, y, 
..).  It is possible to make identity behave exactly like None in map by 
defining it  as

def identity(*args):
   if len(args) == 1:
      return args[0]
   else:
      return args
 
While there is certain cuteness in making identity(...) equivalent to 
(...), it is a bit too cute for my taste.  I am -1 on multi-argument 
identity.

Also placement of identity in operator while map is in builtin, may 
complicate implementation of passthrough map optimization.  While it is 
possible to avoid importing operator in builtin by implementing identity  
in builtin but exporting it only from operator, a more straightforward 
solution would be to keep map and identity in the same module.  This 
logic may be a slippery slope, however, because optimizing filterfalse, 
would suggest that operator.not_ should be moved in the same module as 
the ultimate location for filterfalse. I am +1 on implementing 
optimization for map(identity, ..), +0 on that for filterfalse(not_, 
..), 0 on the location of identity. (BTW, maybe we should implement 
optimization for filter(not_, ..) and drop filterfalse altogether.)

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1673203>
_____________________________________


More information about the Python-bugs-list mailing list