Skip to content

Commit 12083c0

Browse files
[3.12] Run more inspect.rst code snippets in CI (GH-112654) (#112655)
Run more `inspect.rst` code snippets in CI (GH-112654) (cherry picked from commit 4ed46d2) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 34d57d5 commit 12083c0

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

Doc/library/inspect.rst

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,11 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
392392
Return ``True`` if the object can be used in :keyword:`await` expression.
393393

394394
Can also be used to distinguish generator-based coroutines from regular
395-
generators::
395+
generators:
396+
397+
.. testcode::
398+
399+
import types
396400

397401
def gen():
398402
yield
@@ -409,13 +413,15 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
409413
.. function:: isasyncgenfunction(object)
410414

411415
Return ``True`` if the object is an :term:`asynchronous generator` function,
412-
for example::
416+
for example:
413417

414-
>>> async def agen():
415-
... yield 1
416-
...
417-
>>> inspect.isasyncgenfunction(agen)
418-
True
418+
.. doctest::
419+
420+
>>> async def agen():
421+
... yield 1
422+
...
423+
>>> inspect.isasyncgenfunction(agen)
424+
True
419425

420426
.. versionadded:: 3.6
421427

@@ -968,18 +974,20 @@ function.
968974
For variable-keyword arguments (``**kwargs``) the default is an
969975
empty dict.
970976

971-
::
977+
.. doctest::
972978

973-
>>> def foo(a, b='ham', *args): pass
974-
>>> ba = inspect.signature(foo).bind('spam')
975-
>>> ba.apply_defaults()
976-
>>> ba.arguments
977-
{'a': 'spam', 'b': 'ham', 'args': ()}
979+
>>> def foo(a, b='ham', *args): pass
980+
>>> ba = inspect.signature(foo).bind('spam')
981+
>>> ba.apply_defaults()
982+
>>> ba.arguments
983+
{'a': 'spam', 'b': 'ham', 'args': ()}
978984

979985
.. versionadded:: 3.5
980986

981987
The :attr:`args` and :attr:`kwargs` properties can be used to invoke
982-
functions::
988+
functions:
989+
990+
.. testcode::
983991

984992
def test(a, *, b):
985993
...
@@ -1098,20 +1106,22 @@ Classes and functions
10981106
``**`` arguments, if any) to their values from *args* and *kwds*. In case of
10991107
invoking *func* incorrectly, i.e. whenever ``func(*args, **kwds)`` would raise
11001108
an exception because of incompatible signature, an exception of the same type
1101-
and the same or similar message is raised. For example::
1102-
1103-
>>> from inspect import getcallargs
1104-
>>> def f(a, b=1, *pos, **named):
1105-
... pass
1106-
...
1107-
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
1108-
True
1109-
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
1110-
True
1111-
>>> getcallargs(f)
1112-
Traceback (most recent call last):
1113-
...
1114-
TypeError: f() missing 1 required positional argument: 'a'
1109+
and the same or similar message is raised. For example:
1110+
1111+
.. doctest::
1112+
1113+
>>> from inspect import getcallargs
1114+
>>> def f(a, b=1, *pos, **named):
1115+
... pass
1116+
...
1117+
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
1118+
True
1119+
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
1120+
True
1121+
>>> getcallargs(f)
1122+
Traceback (most recent call last):
1123+
...
1124+
TypeError: f() missing 1 required positional argument: 'a'
11151125

11161126
.. versionadded:: 3.2
11171127

0 commit comments

Comments
 (0)