]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-21314: Add a FAQ entry about positional only parameters (GH-10641)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 10 Mar 2019 11:36:18 +0000 (04:36 -0700)
committerGitHub <noreply@github.com>
Sun, 10 Mar 2019 11:36:18 +0000 (04:36 -0700)
(cherry picked from commit 1aeeaeb79efa4de41f97b58547e23c2965ecabc5)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Doc/faq/programming.rst
Doc/library/functions.rst
Doc/library/inspect.rst
Misc/NEWS.d/next/Documentation/2018-11-21-23-01-37.bpo-21314.PG33VT.rst [new file with mode: 0644]

index 7bc00ff7e69debc8d1049fd6dabf93f7ba587602..31614189a62d2ceb723e445045c776d948259695 100644 (file)
@@ -767,6 +767,41 @@ Yes.  Usually this is done by nesting :keyword:`lambda` within
 Don't try this at home, kids!
 
 
+.. _faq-positional-only-arguments:
+
+What does the slash(/) in the parameter list of a function mean?
+----------------------------------------------------------------
+
+A slash in the argument list of a function denotes that the parameters prior to
+it are positional-only.  Positional-only parameters are the ones without an
+externally-usable name.  Upon calling a function that accepts positional-only
+parameters, arguments are mapped to parameters based solely on their position.
+For example, :func:`pow` is a function that accepts positional-only parameters.
+Its documentation looks like this::
+
+   >>> help(pow)
+   Help on built-in function pow in module builtins:
+
+   pow(x, y, z=None, /)
+      Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
+
+      Some types, such as ints, are able to use a more efficient algorithm when
+      invoked using the three argument form.
+
+The slash at the end of the parameter list means that all three parameters are
+positional-only. Thus, calling :func:`pow` with keyword aguments would lead to
+an error::
+
+   >>> pow(x=3, y=4)
+   Traceback (most recent call last):
+     File "<stdin>", line 1, in <module>
+   TypeError: pow() takes no keyword arguments
+
+Note that as of this writing this is only documentational and no valid syntax
+in Python, although there is :pep:`570`, which proposes a syntax for
+position-only parameters in Python.
+
+
 Numbers and strings
 ===================
 
index b28f28f2142ab3792c4d9882a5e0a0c36b729373..9326b8d0fe7d70dd4c528931178abb87fa7da86b 100644 (file)
@@ -668,6 +668,11 @@ are always available.  They are listed here in alphabetical order.
    topic, and a help page is printed on the console.  If the argument is any other
    kind of object, a help page on the object is generated.
 
+   Note that if a slash(/) appears in the parameter list of a function, when
+   invoking :func:`help`, it means that the parameters prior to the slash are
+   positional-only. For more info, see
+   :ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
+
    This function is added to the built-in namespace by the :mod:`site` module.
 
    .. versionchanged:: 3.4
index f985eeb4f53b7175edab034293683f21c7b1bc36..18cbacf3e8db5272cf6501cd92aa097749473885 100644 (file)
@@ -559,6 +559,10 @@ function.
    Raises :exc:`ValueError` if no signature can be provided, and
    :exc:`TypeError` if that type of object is not supported.
 
+   A slash(/) in the signature of a function denotes that the parameters prior
+   to it are positional-only. For more info, see
+   :ref:`the FAQ entry on positional-only parameters <faq-positional-only-arguments>`.
+
    .. versionadded:: 3.5
       ``follow_wrapped`` parameter. Pass ``False`` to get a signature of
       ``callable`` specifically (``callable.__wrapped__`` will not be used to
diff --git a/Misc/NEWS.d/next/Documentation/2018-11-21-23-01-37.bpo-21314.PG33VT.rst b/Misc/NEWS.d/next/Documentation/2018-11-21-23-01-37.bpo-21314.PG33VT.rst
new file mode 100644 (file)
index 0000000..83080a3
--- /dev/null
@@ -0,0 +1,3 @@
+A new entry was added to the Core Language Section of the Programming FAQ,
+which explaines the usage of slash(/) in the signature of a function. Patch
+by Lysandros Nikolaou