Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ def test_staticmethod(*args): # NOQA
((('args', ..., ..., 'var_positional'),), ...))
self.assertEqual(self.signature(A.f3),
((('args', ..., ..., 'var_positional'),), ...))
self.assertEqual(self.signature(A.f4),
self.assertEqual(self.signature(A.f4),
((('args', ..., ..., 'var_positional'),
('kwargs', ..., ..., 'var_keyword')), ...))
@cpython_only
Expand Down Expand Up @@ -3523,7 +3523,7 @@ def test_builtins_have_signatures(self):
needs_semantic_update = {"round"}
no_signature |= needs_semantic_update
# These need *args support in Argument Clinic
needs_varargs = {"min", "max", "print", "__build_class__"}
needs_varargs = {"min", "max", "noop", "print", "__build_class__"}
no_signature |= needs_varargs
# These simply weren't covered in the initial AC conversion
# for builtin callables
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PEP 559 - Built-in noop() function.
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