Skip to content

Commit 8744bcb

Browse files
committed
Minor doc edits and add doctests
1 parent 8d6c28e commit 8744bcb

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Doc/library/functools.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,21 @@ The :mod:`functools` module defines the following functions:
346346
Roughly equivalent to::
347347

348348
def partial(func, /, *args, **keywords):
349-
def newfunc(*fargs, **fkeywords):
350-
newkeywords = {**keywords, **fkeywords}
351-
return func(*args, *fargs, **newkeywords)
349+
def newfunc(*more_args, **more_keywords):
350+
return func(*args, *more_args, **keywords, **more_keywords)
352351
newfunc.func = func
353352
newfunc.args = args
354353
newfunc.keywords = keywords
355354
return newfunc
356355

357-
The :func:`partial` is used for partial function application which "freezes"
356+
The :func:`partial` function is used for partial function application which "freezes"
358357
some portion of a function's arguments and/or keywords resulting in a new object
359358
with a simplified signature. For example, :func:`partial` can be used to create
360359
a callable that behaves like the :func:`int` function where the *base* argument
361-
defaults to two:
360+
defaults to ``2``:
361+
362+
.. doctest::
362363

363-
>>> from functools import partial
364364
>>> basetwo = partial(int, base=2)
365365
>>> basetwo.__doc__ = 'Convert base 2 string to an int.'
366366
>>> basetwo('10010')
@@ -372,7 +372,8 @@ The :mod:`functools` module defines the following functions:
372372

373373
If :data:`!Placeholder` sentinels are present, all of them must be filled at call time:
374374

375-
>>> from functools import partial, Placeholder
375+
.. doctest::
376+
376377
>>> say_to_world = partial(print, Placeholder, Placeholder, "world!")
377378
>>> say_to_world('Hello', 'dear')
378379
Hello dear world!
@@ -386,6 +387,8 @@ The :mod:`functools` module defines the following functions:
386387
A place for positional argument can be retained by inserting new
387388
:data:`!Placeholder` sentinel to the place held by previous :data:`!Placeholder`:
388389

390+
.. doctest::
391+
389392
>>> from functools import partial, Placeholder as _
390393
>>> remove = partial(str.replace, _, _, '')
391394
>>> message = 'Hello, dear dear world!'
@@ -789,6 +792,4 @@ have three read-only attributes:
789792
:class:`partial` objects are like :class:`function` objects in that they are
790793
callable, weak referenceable, and can have attributes. There are some important
791794
differences. For instance, the :attr:`~definition.__name__` and :attr:`__doc__` attributes
792-
are not created automatically. Also, :class:`partial` objects defined in
793-
classes behave like static methods and do not transform into bound methods
794-
during instance attribute look-up.
795+
are not created automatically.

0 commit comments

Comments
 (0)