Index: Lib/test/test_operator.py =================================================================== --- Lib/test/test_operator.py (revision 54535) +++ Lib/test/test_operator.py (working copy) @@ -360,6 +360,11 @@ self.failIf(operator.is_not(a, b)) self.failUnless(operator.is_not(a,c)) + def test_identity(self): + ob = object() + self.assertEqual(operator.identity(ob), ob) + self.assertEqual(operator.is_(operator.identity(ob), ob), True) + def test_attrgetter(self): class A: pass Index: Doc/lib/liboperator.tex =================================================================== --- Doc/lib/liboperator.tex (revision 54535) +++ Doc/lib/liboperator.tex (working copy) @@ -74,7 +74,12 @@ \versionadded{2.3} \end{funcdesc} +\begin{funcdesc}{identity}{a} +Return \code{\var{a}}. The identity function. +\versionadded{2.6} +\end{funcdesc} + The mathematical and bitwise operations are the most numerous: \begin{funcdesc}{abs}{o} Index: Modules/operator.c =================================================================== --- Modules/operator.c (revision 54535) +++ Modules/operator.c (working copy) @@ -205,6 +205,13 @@ Py_RETURN_NONE; } +static PyObject * +identity(PyObject *dummy, PyObject *ob) +{ + Py_INCREF(ob); + return ob; +} + #undef spam1 #undef spam2 #undef spam1o @@ -236,6 +243,8 @@ "countOf(a, b) -- Return the number of times b occurs in a.") spam1o(isMappingType, "isMappingType(a) -- Return True if a has a mapping type, False otherwise.") +spam1o(identity, + "identity(a) -- Return the object a.") spam1(is_, "is_(a, b) -- Same as a is b.") spam1(is_not, "is_not(a, b) -- Same as a is not b.") Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 54535) +++ Misc/NEWS (working copy) @@ -657,6 +657,8 @@ - Bug #1633621: if curses.resizeterm() or curses.resize_term() is called, update _curses.LINES, _curses.COLS, curses.LINES and curses.COLS. +- Feature Request #1673203: add the identity function to the operator module. + Tests -----