Skip to content

Commit

Permalink
Built-in noop()
Browse files Browse the repository at this point in the history
  • Loading branch information
warsaw committed Sep 8, 2017
1 parent e6eb48c commit ecd3faf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ are always available. They are listed here in alphabetical order.
=================== ================= ================== ================ ====================
.. .. Built-in Functions .. ..
=================== ================= ================== ================ ====================
:func:`abs` |func-dict|_ :func:`help` :func:`min` :func:`setattr`
:func:`all` :func:`dir` :func:`hex` :func:`next` :func:`slice`
:func:`any` :func:`divmod` :func:`id` :func:`object` :func:`sorted`
:func:`ascii` :func:`enumerate` :func:`input` :func:`oct` :func:`staticmethod`
:func:`bin` :func:`eval` :func:`int` :func:`open` |func-str|_
:func:`bool` :func:`exec` :func:`isinstance` :func:`ord` :func:`sum`
|func-bytearray|_ :func:`filter` :func:`issubclass` :func:`pow` :func:`super`
|func-bytes|_ :func:`float` :func:`iter` :func:`print` |func-tuple|_
:func:`callable` :func:`format` :func:`len` :func:`property` :func:`type`
:func:`chr` |func-frozenset|_ |func-list|_ |func-range|_ :func:`vars`
:func:`classmethod` :func:`getattr` :func:`locals` :func:`repr` :func:`zip`
:func:`compile` :func:`globals` :func:`map` :func:`reversed` :func:`__import__`
:func:`complex` :func:`hasattr` :func:`max` :func:`round`
:func:`delattr` :func:`hash` |func-memoryview|_ |func-set|_
:func:`abs` |func-dict|_ :func:`help` :func:`min` |func-set|_
:func:`all` :func:`dir` :func:`hex` :func:`next` :func:`setattr`
:func:`any` :func:`divmod` :func:`id` :func:`noop` :func:`slice`
:func:`ascii` :func:`enumerate` :func:`input` :func:`object` :func:`sorted`
:func:`bin` :func:`eval` :func:`int` :func:`oct` :func:`staticmethod`
:func:`bool` :func:`exec` :func:`isinstance` :func:`open` |func-str|_
|func-bytearray|_ :func:`filter` :func:`issubclass` :func:`ord` :func:`sum`
|func-bytes|_ :func:`float` :func:`iter` :func:`pow` :func:`super`
:func:`callable` :func:`format` :func:`len` :func:`print` |func-tuple|_
:func:`chr` |func-frozenset|_ |func-list|_ :func:`property` :func:`type`
:func:`classmethod` :func:`getattr` :func:`locals` |func-range|_ :func:`vars`
:func:`compile` :func:`globals` :func:`map` :func:`repr` :func:`zip`
:func:`complex` :func:`hasattr` :func:`max` :func:`reversed` :func:`__import__`
:func:`delattr` :func:`hash` |func-memoryview|_ :func:`round`
=================== ================= ================== ================ ====================

.. using :func:`dict` would create a link to another page, so local targets are
Expand Down Expand Up @@ -889,6 +889,12 @@ are always available. They are listed here in alphabetical order.
if the iterator is exhausted, otherwise :exc:`StopIteration` is raised.


.. function:: noop(*args, **kws)

Do nothing but return ``None``.

.. versionadded:: 3.7

.. class:: object()

Return a new featureless object. :class:`object` is a base for all classes.
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@ def gen():
self.assertRaises(StopIteration, next, it)
self.assertEqual(next(it, 42), 42)

def test_noop(self):
self.assertIsNone(noop())
self.assertIsNone(noop(1))
self.assertIsNone(noop(1, 2))
self.assertIsNone(noop(a=1))
self.assertIsNone(noop(a=1, b=3))
self.assertIsNone(noop(2, 4, a=1, b=3))

def test_oct(self):
self.assertEqual(oct(100), '0o144')
self.assertEqual(oct(-100), '-0o144')
Expand Down
14 changes: 14 additions & 0 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,19 @@ Return the next item from the iterator. If default is given and the iterator\n\
is exhausted, it is returned instead of raising StopIteration.");


static PyObject *
builtin_noop(PyObject *self, PyObject *args, PyObject *keywords)
{
Py_RETURN_NONE;
}


PyDoc_STRVAR(noop_doc,
"noop(*args, **kws)\n\
\n\
Do nothing except return None.")


/*[clinic input]
setattr as builtin_setattr
Expand Down Expand Up @@ -2644,6 +2657,7 @@ static PyMethodDef builtin_methods[] = {
{"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEYWORDS, max_doc},
{"min", (PyCFunction)builtin_min, METH_VARARGS | METH_KEYWORDS, min_doc},
{"next", (PyCFunction)builtin_next, METH_FASTCALL, next_doc},
{"noop", (PyCFunction)builtin_noop, METH_VARARGS | METH_KEYWORDS, noop_doc},
BUILTIN_OCT_METHODDEF
BUILTIN_ORD_METHODDEF
BUILTIN_POW_METHODDEF
Expand Down

0 comments on commit ecd3faf

Please sign in to comment.