Skip to content

Commit 8ed75cd

Browse files
committed
#22613: minor other fixes in library docs (thanks Jacques Ducasse)
1 parent 2677fae commit 8ed75cd

9 files changed

Lines changed: 35 additions & 30 deletions

File tree

Doc/library/collections.abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ particular functionality, for example::
134134

135135
Several of the ABCs are also useful as mixins that make it easier to develop
136136
classes supporting container APIs. For example, to write a class supporting
137-
the full :class:`Set` API, it only necessary to supply the three underlying
137+
the full :class:`Set` API, it is only necessary to supply the three underlying
138138
abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`.
139139
The ABC supplies the remaining methods such as :meth:`__and__` and
140140
:meth:`isdisjoint`::

Doc/library/collections.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ customize a prototype instance:
908908
>>> janes_account = default_account._replace(owner='Jane')
909909

910910
Enumerated constants can be implemented with named tuples, but it is simpler
911-
and more efficient to use a simple :class:`~enum.Enum` :
911+
and more efficient to use a simple :class:`~enum.Enum`:
912912

913913
>>> Status = namedtuple('Status', 'open pending closed')._make(range(3))
914914
>>> Status.open, Status.pending, Status.closed
@@ -917,6 +917,9 @@ and more efficient to use a simple :class:`~enum.Enum` :
917917
>>> class Status(Enum):
918918
... open, pending, closed = range(3)
919919

920+
921+
.. seealso::
922+
920923
* `Recipe for named tuple abstract base class with a metaclass mix-in
921924
<http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/>`_
922925
by Jan Kaliszewski. Besides providing an :term:`abstract base class` for

Doc/library/ctypes.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ Utility functions
18331833
.. function:: find_msvcrt()
18341834
:module: ctypes.util
18351835

1836-
Windows only: return the filename of the VC runtype library used by Python,
1836+
Windows only: return the filename of the VC runtime library used by Python,
18371837
and by the extension modules. If the name of the library cannot be
18381838
determined, ``None`` is returned.
18391839

@@ -2335,11 +2335,6 @@ other data types containing pointer type fields.
23352335
and so on). Later assignments to the :attr:`_fields_` class variable will
23362336
raise an AttributeError.
23372337

2338-
Structure and union subclass constructors accept both positional and named
2339-
arguments. Positional arguments are used to initialize the fields in the
2340-
same order as they appear in the :attr:`_fields_` definition, named
2341-
arguments are used to initialize the fields with the corresponding name.
2342-
23432338
It is possible to defined sub-subclasses of structure types, they inherit
23442339
the fields of the base class plus the :attr:`_fields_` defined in the
23452340
sub-subclass, if any.

Doc/library/inspect.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -750,17 +750,20 @@ Classes and functions
750750
:func:`getargspec` or :func:`getfullargspec`.
751751

752752
The first seven arguments are (``args``, ``varargs``, ``varkw``,
753-
``defaults``, ``kwonlyargs``, ``kwonlydefaults``, ``annotations``). The
754-
other five arguments are the corresponding optional formatting functions
755-
that are called to turn names and values into strings. The last argument
756-
is an optional function to format the sequence of arguments. For example::
753+
``defaults``, ``kwonlyargs``, ``kwonlydefaults``, ``annotations``).
757754

758-
>>> from inspect import formatargspec, getfullargspec
759-
>>> def f(a: int, b: float):
760-
... pass
761-
...
762-
>>> formatargspec(*getfullargspec(f))
763-
'(a: int, b: float)'
755+
The other six arguments are functions that are called to turn argument names,
756+
``*`` argument name, ``**`` argument name, default values, return annotation
757+
and individual annotations into strings, respectively.
758+
759+
For example:
760+
761+
>>> from inspect import formatargspec, getfullargspec
762+
>>> def f(a: int, b: float):
763+
... pass
764+
...
765+
>>> formatargspec(*getfullargspec(f))
766+
'(a: int, b: float)'
764767

765768

766769
.. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue])

Doc/library/pydoc.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ The :mod:`pydoc` module automatically generates documentation from Python
2020
modules. The documentation can be presented as pages of text on the console,
2121
served to a Web browser, or saved to HTML files.
2222

23+
For modules, classes, functions and methods, the displayed documentation is
24+
derived from the docstring (i.e. the :attr:`__doc__` attribute) of the object,
25+
and recursively of its documentable members. If there is no docstring,
26+
:mod:`pydoc` tries to obtain a description from the block of comment lines just
27+
above the definition of the class, function or method in the source file, or at
28+
the top of the module (see :func:`inspect.getcomments`).
29+
2330
The built-in function :func:`help` invokes the online help system in the
2431
interactive interpreter, which uses :mod:`pydoc` to generate its documentation
2532
as text on the console. The same text documentation can also be viewed from

Doc/library/reprlib.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,3 @@ for file objects could be added::
156156

157157
aRepr = MyRepr()
158158
print(aRepr.repr(sys.stdin)) # prints '<stdin>'
159-

Doc/library/runpy.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ The :mod:`runpy` module provides two functions:
127127
supplied path, and ``__spec__``, ``__cached__``, ``__loader__`` and
128128
``__package__`` will all be set to :const:`None`.
129129

130-
``__spec__`` will be set to :const:`None` if the supplied path is a
131-
direct path to a script (as source or as precompiled bytecode).
132-
133130
If the supplied path is a reference to a valid sys.path entry, then
134131
``__spec__`` will be set appropriately for the imported ``__main__``
135132
module (that is, ``__spec__.name`` will always be ``__main__``).

Doc/library/tempfile.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ The module defines the following user-callable items:
192192
>>> os.path.exists(f.name)
193193
False
194194

195-
The module uses two global variables that tell it how to construct a
195+
The module uses a global variable that tell it how to construct a
196196
temporary name. They are initialized at the first call to any of the
197197
functions above. The caller may change them, but this is discouraged; use
198198
the appropriate function arguments, instead.

Doc/library/unittest.mock.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,19 @@ the `new_callable` argument to `patch`.
461461
.. attribute:: side_effect
462462

463463
This can either be a function to be called when the mock is called,
464-
or an exception (class or instance) to be raised.
464+
an iterable or an exception (class or instance) to be raised.
465465

466466
If you pass in a function it will be called with same arguments as the
467467
mock and unless the function returns the :data:`DEFAULT` singleton the
468468
call to the mock will then return whatever the function returns. If the
469469
function returns :data:`DEFAULT` then the mock will return its normal
470470
value (from the :attr:`return_value`).
471471

472+
If you pass in an iterable, it is used to retrieve an iterator which
473+
must yield a value on every call. This value can either be an exception
474+
instance to be raised, or a value to be returned from the call to the
475+
mock (:data:`DEFAULT` handling is identical to the function case).
476+
472477
An example of a mock that raises an exception (to test exception
473478
handling of an API):
474479

@@ -486,11 +491,7 @@ the `new_callable` argument to `patch`.
486491
>>> mock(), mock(), mock()
487492
(3, 2, 1)
488493

489-
The :attr:`side_effect` function is called with the same arguments as the
490-
mock (so it is wise for it to take arbitrary args and keyword
491-
arguments) and whatever it returns is used as the return value for
492-
the call. The exception is if :attr:`side_effect` returns :data:`DEFAULT`,
493-
in which case the normal :attr:`return_value` is used.
494+
Using a callable:
494495

495496
>>> mock = Mock(return_value=3)
496497
>>> def side_effect(*args, **kwargs):
@@ -1011,7 +1012,7 @@ patch
10111012
used.
10121013

10131014
A more powerful form of *spec* is *autospec*. If you set ``autospec=True``
1014-
then the mock with be created with a spec from the object being replaced.
1015+
then the mock will be created with a spec from the object being replaced.
10151016
All attributes of the mock will also have the spec of the corresponding
10161017
attribute of the object being replaced. Methods and functions being mocked
10171018
will have their arguments checked and will raise a :exc:`TypeError` if they are

0 commit comments

Comments
 (0)