◐ Shell
clean mode source ↗

Message 55035 - Python tracker

Raymond, please make a pronouncement.

+1 on adding it to the operator module.  Lots of one liners go there.
-1000 to having it take more than one argument.  If I saw this
  identity(ob, 42)
for the first time (or second, or ...) I would have to look up what
it does.  As a plain identity function it is obvious.

Patch to operator.c, liboperator.tex, test_operator.py, NEWS attached.
Raymond, there isn't a good section in the doc for this function so I added it to the logical operators.  The fact that there isn't a good section for it might be a mark against it being included.

It is a couple times faster than the python version which isn't exciting.

sprat:~/src/python-rw> ./python Lib/timeit.py -s "from operator import identity" "identity(None)"
10000000 loops, best of 3: 0.161 usec per loop
sprat:~/src/python-rw> ./python Lib/timeit.py -s "def identity(ob): return ob" "identity(None)"
1000000 loops, best of 3: 0.421 usec per loop

File Added: identity.patch