@@ -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
@@ -985,18 +991,20 @@ function.
985991 For variable-keyword arguments (``**kwargs ``) the default is an
986992 empty dict.
987993
988- ::
994+ .. doctest ::
989995
990- >>> def foo(a, b='ham', *args): pass
991- >>> ba = inspect.signature(foo).bind('spam')
992- >>> ba.apply_defaults()
993- >>> ba.arguments
994- {'a': 'spam', 'b': 'ham', 'args': ()}
996+ >>> def foo (a , b = ' ham' , * args ): pass
997+ >>> ba = inspect.signature(foo).bind(' spam' )
998+ >>> ba.apply_defaults()
999+ >>> ba.arguments
1000+ {'a': 'spam', 'b': 'ham', 'args': ()}
9951001
9961002 .. versionadded :: 3.5
9971003
9981004 The :attr: `args ` and :attr: `kwargs ` properties can be used to invoke
999- functions::
1005+ functions:
1006+
1007+ .. testcode ::
10001008
10011009 def test(a, *, b):
10021010 ...
@@ -1115,20 +1123,22 @@ Classes and functions
11151123 ``** `` arguments, if any) to their values from *args * and *kwds *. In case of
11161124 invoking *func * incorrectly, i.e. whenever ``func(*args, **kwds) `` would raise
11171125 an exception because of incompatible signature, an exception of the same type
1118- and the same or similar message is raised. For example::
1119-
1120- >>> from inspect import getcallargs
1121- >>> def f(a, b=1, *pos, **named):
1122- ... pass
1123- ...
1124- >>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
1125- True
1126- >>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
1127- True
1128- >>> getcallargs(f)
1129- Traceback (most recent call last):
1130- ...
1131- TypeError: f() missing 1 required positional argument: 'a'
1126+ and the same or similar message is raised. For example:
1127+
1128+ .. doctest ::
1129+
1130+ >>> from inspect import getcallargs
1131+ >>> def f (a , b = 1 , * pos , ** named ):
1132+ ... pass
1133+ ...
1134+ >>> getcallargs(f, 1 , 2 , 3 ) == {' a' : 1 , ' named' : {}, ' b' : 2 , ' pos' : (3 ,)}
1135+ True
1136+ >>> getcallargs(f, a = 2 , x = 4 ) == {' a' : 2 , ' named' : {' x' : 4 }, ' b' : 1 , ' pos' : ()}
1137+ True
1138+ >>> getcallargs(f)
1139+ Traceback (most recent call last):
1140+ ...
1141+ TypeError: f() missing 1 required positional argument: 'a'
11321142
11331143 .. versionadded :: 3.2
11341144
0 commit comments