Skip to content

Latest commit

 

History

History
544 lines (333 loc) · 16.7 KB

File metadata and controls

544 lines (333 loc) · 16.7 KB
 
May 8, 2024
May 8, 2024
1
:mod:`!types` --- Dynamic type creation and names for built-in types
2
====================================================================
Aug 15, 2007
Aug 15, 2007
3
4
.. module:: types
5
:synopsis: Names for built-in types.
6
Jan 27, 2011
Jan 27, 2011
7
**Source code:** :source:`Lib/types.py`
8
9
--------------
Aug 15, 2007
Aug 15, 2007
10
Dec 24, 2018
Dec 24, 2018
11
This module defines utility functions to assist in dynamic creation of
May 19, 2012
May 19, 2012
12
new types.
13
14
It also defines names for some object types that are used by the standard
Aug 23, 2008
Aug 23, 2008
15
Python interpreter, but not exposed as builtins like :class:`int` or
May 19, 2012
May 19, 2012
16
:class:`str` are.
17
Feb 25, 2014
Feb 25, 2014
18
Finally, it provides some additional type-related utility classes and functions
19
that are not fundamental enough to be builtins.
20
May 19, 2012
May 19, 2012
21
22
Dynamic Type Creation
23
---------------------
24
25
.. function:: new_class(name, bases=(), kwds=None, exec_body=None)
26
27
Creates a class object dynamically using the appropriate metaclass.
28
May 30, 2012
May 30, 2012
29
The first three arguments are the components that make up a class
30
definition header: the class name, the base classes (in order), the
31
keyword arguments (such as ``metaclass``).
May 19, 2012
May 19, 2012
32
May 30, 2012
May 30, 2012
33
The *exec_body* argument is a callback that is used to populate the
34
freshly created class namespace. It should accept the class namespace
35
as its sole argument and update the namespace directly with the class
36
contents. If no callback is provided, it has the same effect as passing
May 1, 2021
May 1, 2021
37
in ``lambda ns: None``.
May 19, 2012
May 19, 2012
38
May 22, 2012
May 22, 2012
39
.. versionadded:: 3.3
40
May 19, 2012
May 19, 2012
41
.. function:: prepare_class(name, bases=(), kwds=None)
42
43
Calculates the appropriate metaclass and creates the class namespace.
44
May 30, 2012
May 30, 2012
45
The arguments are the components that make up a class definition header:
46
the class name, the base classes (in order) and the keyword arguments
47
(such as ``metaclass``).
May 19, 2012
May 19, 2012
48
49
The return value is a 3-tuple: ``metaclass, namespace, kwds``
50
May 30, 2012
May 30, 2012
51
*metaclass* is the appropriate metaclass, *namespace* is the
52
prepared class namespace and *kwds* is an updated copy of the passed
53
in *kwds* argument with any ``'metaclass'`` entry removed. If no *kwds*
54
argument is passed in, this will be an empty dict.
May 19, 2012
May 19, 2012
55
May 22, 2012
May 22, 2012
56
.. versionadded:: 3.3
May 19, 2012
May 19, 2012
57
Sep 5, 2016
Sep 5, 2016
58
.. versionchanged:: 3.6
59
60
The default value for the ``namespace`` element of the returned
Sep 8, 2016
Sep 8, 2016
61
tuple has changed. Now an insertion-order-preserving mapping is
May 8, 2018
May 8, 2018
62
used when the metaclass does not have a ``__prepare__`` method.
Sep 5, 2016
Sep 5, 2016
63
May 19, 2012
May 19, 2012
64
.. seealso::
65
May 30, 2012
May 30, 2012
66
:ref:`metaclasses`
67
Full details of the class creation process supported by these functions
68
May 19, 2012
May 19, 2012
69
:pep:`3115` - Metaclasses in Python 3000
70
Introduced the ``__prepare__`` namespace hook
71
May 8, 2018
May 8, 2018
72
.. function:: resolve_bases(bases)
73
74
Resolve MRO entries dynamically as specified by :pep:`560`.
75
76
This function looks for items in *bases* that are not instances of
77
:class:`type`, and returns a tuple where each such object that has
Apr 11, 2023
Apr 11, 2023
78
an :meth:`~object.__mro_entries__` method is replaced with an unpacked result of
May 8, 2018
May 8, 2018
79
calling this method. If a *bases* item is an instance of :class:`type`,
Apr 11, 2023
Apr 11, 2023
80
or it doesn't have an :meth:`!__mro_entries__` method, then it is included in
May 8, 2018
May 8, 2018
81
the return tuple unchanged.
82
83
.. versionadded:: 3.7
84
Apr 23, 2023
Apr 23, 2023
85
.. function:: get_original_bases(cls, /)
86
87
Return the tuple of objects originally given as the bases of *cls* before
88
the :meth:`~object.__mro_entries__` method has been called on any bases
89
(following the mechanisms laid out in :pep:`560`). This is useful for
90
introspecting :ref:`Generics <user-defined-generics>`.
91
92
For classes that have an ``__orig_bases__`` attribute, this
93
function returns the value of ``cls.__orig_bases__``.
Sep 25, 2024
Sep 25, 2024
94
For classes without the ``__orig_bases__`` attribute,
95
:attr:`cls.__bases__ <type.__bases__>` is returned.
Apr 23, 2023
Apr 23, 2023
96
97
Examples::
98
99
from typing import TypeVar, Generic, NamedTuple, TypedDict
100
101
T = TypeVar("T")
102
class Foo(Generic[T]): ...
103
class Bar(Foo[int], float): ...
104
class Baz(list[str]): ...
105
Eggs = NamedTuple("Eggs", [("a", int), ("b", str)])
106
Spam = TypedDict("Spam", {"a": int, "b": str})
107
108
assert Bar.__bases__ == (Foo, float)
109
assert get_original_bases(Bar) == (Foo[int], float)
110
111
assert Baz.__bases__ == (list,)
112
assert get_original_bases(Baz) == (list[str],)
113
114
assert Eggs.__bases__ == (tuple,)
115
assert get_original_bases(Eggs) == (NamedTuple,)
116
117
assert Spam.__bases__ == (dict,)
118
assert get_original_bases(Spam) == (TypedDict,)
119
120
assert int.__bases__ == (object,)
121
assert get_original_bases(int) == (object,)
122
123
.. versionadded:: 3.12
124
May 8, 2018
May 8, 2018
125
.. seealso::
126
127
:pep:`560` - Core support for typing module and generic types
128
May 19, 2012
May 19, 2012
129
130
Standard Interpreter Types
131
--------------------------
132
133
This module provides names for many of the types that are required to
134
implement a Python interpreter. It deliberately avoids including some of
135
the types that arise only incidentally during processing such as the
136
``listiterator`` type.
Aug 23, 2008
Aug 23, 2008
137
Aug 26, 2012
Aug 26, 2012
138
Typical use of these names is for :func:`isinstance` or
May 19, 2012
May 19, 2012
139
:func:`issubclass` checks.
Aug 15, 2007
Aug 15, 2007
140
Jun 3, 2019
Jun 3, 2019
141
142
If you instantiate any of these types, note that signatures may vary between Python versions.
143
May 19, 2012
May 19, 2012
144
Standard names are defined for the following types:
Aug 15, 2007
Aug 15, 2007
145
Sep 22, 2020
Sep 22, 2020
146
.. data:: NoneType
147
148
The type of :data:`None`.
149
150
.. versionadded:: 3.10
151
152
Aug 15, 2007
Aug 15, 2007
153
.. data:: FunctionType
Sep 4, 2007
Sep 4, 2007
154
LambdaType
Aug 15, 2007
Aug 15, 2007
155
May 19, 2012
May 19, 2012
156
The type of user-defined functions and functions created by
157
:keyword:`lambda` expressions.
Aug 15, 2007
Aug 15, 2007
158
Oct 20, 2020
Oct 20, 2020
159
.. audit-event:: function.__new__ code types.FunctionType
160
161
The audit event only occurs for direct instantiation of function objects,
162
and is not raised for normal compilation.
163
Aug 15, 2007
Aug 15, 2007
164
165
.. data:: GeneratorType
166
Sep 11, 2015
Sep 11, 2015
167
The type of :term:`generator`-iterator objects, created by
168
generator functions.
Aug 15, 2007
Aug 15, 2007
169
170
Jun 22, 2015
Jun 22, 2015
171
.. data:: CoroutineType
172
Sep 11, 2015
Sep 11, 2015
173
The type of :term:`coroutine` objects, created by
174
:keyword:`async def` functions.
Jun 22, 2015
Jun 22, 2015
175
176
.. versionadded:: 3.5
177
178
Dec 15, 2016
Dec 15, 2016
179
.. data:: AsyncGeneratorType
180
181
The type of :term:`asynchronous generator`-iterator objects, created by
182
asynchronous generator functions.
183
184
.. versionadded:: 3.6
185
186
Jan 1, 2020
Jan 1, 2020
187
.. class:: CodeType(**kwargs)
Aug 15, 2007
Aug 15, 2007
188
May 6, 2023
May 6, 2023
189
.. index:: pair: built-in function; compile
Aug 15, 2007
Aug 15, 2007
190
Feb 18, 2024
Feb 18, 2024
191
The type of :ref:`code objects <code-objects>` such as returned by :func:`compile`.
Aug 15, 2007
Aug 15, 2007
192
Oct 20, 2020
Oct 20, 2020
193
.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags types.CodeType
Oct 26, 2019
Oct 26, 2019
194
195
Note that the audited arguments may not match the names or positions
Oct 20, 2020
Oct 20, 2020
196
required by the initializer. The audit event only occurs for direct
197
instantiation of code objects, and is not raised for normal compilation.
Aug 15, 2007
Aug 15, 2007
198
Feb 7, 2019
Feb 7, 2019
199
.. data:: CellType
200
201
The type for cell objects: such objects are used as containers for
Oct 8, 2024
Oct 8, 2024
202
a function's :term:`closure variables <closure variable>`.
Feb 7, 2019
Feb 7, 2019
203
204
.. versionadded:: 3.8
205
206
Aug 15, 2007
Aug 15, 2007
207
.. data:: MethodType
208
209
The type of methods of user-defined class instances.
210
211
212
.. data:: BuiltinFunctionType
Sep 4, 2007
Sep 4, 2007
213
BuiltinMethodType
Aug 15, 2007
Aug 15, 2007
214
Aug 23, 2008
Aug 23, 2008
215
The type of built-in functions like :func:`len` or :func:`sys.exit`, and
216
methods of built-in classes. (Here, the term "built-in" means "written in
217
C".)
Aug 15, 2007
Aug 15, 2007
218
219
Apr 25, 2017
Apr 25, 2017
220
.. data:: WrapperDescriptorType
Feb 1, 2017
Feb 1, 2017
221
222
The type of methods of some built-in data types and base classes such as
223
:meth:`object.__init__` or :meth:`object.__lt__`.
224
225
.. versionadded:: 3.7
226
227
228
.. data:: MethodWrapperType
229
230
The type of *bound* methods of some built-in data types and base classes.
231
For example it is the type of :code:`object().__str__`.
232
233
.. versionadded:: 3.7
234
235
Sep 22, 2020
Sep 22, 2020
236
.. data:: NotImplementedType
237
238
The type of :data:`NotImplemented`.
239
240
.. versionadded:: 3.10
241
242
Feb 1, 2017
Feb 1, 2017
243
.. data:: MethodDescriptorType
244
245
The type of methods of some built-in data types such as :meth:`str.join`.
246
247
.. versionadded:: 3.7
Dec 15, 2017
Dec 15, 2017
248
249
250
.. data:: ClassMethodDescriptorType
251
252
The type of *unbound* class methods of some built-in data types such as
253
``dict.__dict__['fromkeys']``.
254
255
.. versionadded:: 3.7
Feb 1, 2017
Feb 1, 2017
256
257
Jun 14, 2013
Jun 14, 2013
258
.. class:: ModuleType(name, doc=None)
Aug 15, 2007
Aug 15, 2007
259
Mar 23, 2021
Mar 23, 2021
260
The type of :term:`modules <module>`. The constructor takes the name of the
Jun 14, 2013
Jun 14, 2013
261
module to be created and optionally its :term:`docstring`.
262
Oct 9, 2024
Oct 9, 2024
263
.. seealso::
Mar 23, 2021
Mar 23, 2021
264
Oct 9, 2024
Oct 9, 2024
265
:ref:`Documentation on module objects <module-objects>`
266
Provides details on the special attributes that can be found on
267
instances of :class:`!ModuleType`.
Mar 23, 2021
Mar 23, 2021
268
Oct 9, 2024
Oct 9, 2024
269
:func:`importlib.util.module_from_spec`
270
Modules created using the :class:`!ModuleType` constructor are
271
created with many of their special attributes unset or set to default
272
values. :func:`!module_from_spec` provides a more robust way of
273
creating :class:`!ModuleType` instances which ensures the various
274
attributes are set appropriately.
Aug 15, 2007
Aug 15, 2007
275
Sep 22, 2020
Sep 22, 2020
276
.. data:: EllipsisType
277
278
The type of :data:`Ellipsis`.
279
280
.. versionadded:: 3.10
281
Oct 31, 2020
Oct 31, 2020
282
.. class:: GenericAlias(t_origin, t_args)
Oct 27, 2020
Oct 27, 2020
283
284
The type of :ref:`parameterized generics <types-genericalias>` such as
285
``list[int]``.
286
Oct 31, 2020
Oct 31, 2020
287
``t_origin`` should be a non-parameterized generic class, such as ``list``,
288
``tuple`` or ``dict``. ``t_args`` should be a :class:`tuple` (possibly of
289
length 1) of types which parameterize ``t_origin``::
290
291
>>> from types import GenericAlias
292
293
>>> list[int] == GenericAlias(list, (int,))
294
True
295
>>> dict[str, int] == GenericAlias(dict, (str, int))
296
True
297
Oct 27, 2020
Oct 27, 2020
298
.. versionadded:: 3.9
299
Dec 18, 2020
Dec 18, 2020
300
.. versionchanged:: 3.9.2
301
This type can now be subclassed.
302
Apr 25, 2023
Apr 25, 2023
303
.. seealso::
304
305
:ref:`Generic Alias Types<types-genericalias>`
306
In-depth documentation on instances of :class:`!types.GenericAlias`
307
308
:pep:`585` - Type Hinting Generics In Standard Collections
309
Introducing the :class:`!types.GenericAlias` class
Dec 18, 2020
Dec 18, 2020
310
Dec 9, 2021
Dec 9, 2021
311
.. class:: UnionType
Oct 5, 2020
Oct 5, 2020
312
313
The type of :ref:`union type expressions<types-union>`.
314
315
.. versionadded:: 3.10
Sep 22, 2020
Sep 22, 2020
316
Mar 4, 2025
Mar 4, 2025
317
.. versionchanged:: 3.14
318
319
This is now an alias for :class:`typing.Union`.
320
Feb 13, 2018
Feb 13, 2018
321
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
Aug 15, 2007
Aug 15, 2007
322
Feb 20, 2023
Feb 20, 2023
323
The type of traceback objects such as found in ``sys.exception().__traceback__``.
Aug 15, 2007
Aug 15, 2007
324
Feb 13, 2018
Feb 13, 2018
325
See :ref:`the language reference <traceback-objects>` for details of the
326
available attributes and operations, and guidance on creating tracebacks
327
dynamically.
328
Aug 15, 2007
Aug 15, 2007
329
330
.. data:: FrameType
331
Dec 9, 2023
Dec 9, 2023
332
The type of :ref:`frame objects <frame-objects>` such as found in
333
:attr:`tb.tb_frame <traceback.tb_frame>` if ``tb`` is a traceback object.
Feb 13, 2018
Feb 13, 2018
334
Aug 15, 2007
Aug 15, 2007
335
Jul 20, 2025
Jul 20, 2025
336
.. data:: FrameLocalsProxyType
337
338
The type of frame locals proxy objects, as found on the
339
:attr:`frame.f_locals` attribute.
340
Oct 14, 2025
Oct 14, 2025
341
.. versionadded:: 3.15
Jul 20, 2025
Jul 20, 2025
342
343
.. seealso:: :pep:`667`
344
345
Feb 12, 2026
Feb 12, 2026
346
.. data:: LazyImportType
347
348
The type of lazy import proxy objects. These objects are created when a
349
module is lazily imported and serve as placeholders until the module is
350
actually accessed. This type can be used to detect lazy imports
351
programmatically.
352
Mar 10, 2026
Mar 10, 2026
353
.. versionadded:: 3.15
Feb 12, 2026
Feb 12, 2026
354
355
.. seealso:: :pep:`810`
356
357
Aug 15, 2007
Aug 15, 2007
358
.. data:: GetSetDescriptorType
359
Apr 9, 2008
Apr 9, 2008
360
The type of objects defined in extension modules with ``PyGetSetDef``, such
Dec 5, 2023
Dec 5, 2023
361
as :attr:`FrameType.f_locals <frame.f_locals>` or ``array.array.typecode``.
362
This type is used as
Apr 9, 2008
Apr 9, 2008
363
descriptor for object attributes; it has the same purpose as the
364
:class:`property` type, but for classes defined in extension modules.
Aug 15, 2007
Aug 15, 2007
365
366
367
.. data:: MemberDescriptorType
368
Apr 9, 2008
Apr 9, 2008
369
The type of objects defined in extension modules with ``PyMemberDef``, such
370
as ``datetime.timedelta.days``. This type is used as descriptor for simple C
371
data members which use standard conversion functions; it has the same purpose
372
as the :class:`property` type, but for classes defined in extension modules.
Oct 27, 2009
Oct 27, 2009
373
Jan 24, 2024
Jan 24, 2024
374
In addition, when a class is defined with a :attr:`~object.__slots__` attribute, then for
375
each slot, an instance of :class:`!MemberDescriptorType` will be added as an attribute
Sep 25, 2024
Sep 25, 2024
376
on the class. This allows the slot to appear in the class's :attr:`~type.__dict__`.
Jan 24, 2024
Jan 24, 2024
377
Oct 27, 2009
Oct 27, 2009
378
.. impl-detail::
379
380
In other implementations of Python, this type may be identical to
381
``GetSetDescriptorType``.
Apr 15, 2012
Apr 15, 2012
382
383
.. class:: MappingProxyType(mapping)
384
385
Read-only proxy of a mapping. It provides a dynamic view on the mapping's
386
entries, which means that when the mapping changes, the view reflects these
387
changes.
388
389
.. versionadded:: 3.3
390
Mar 7, 2020
Mar 7, 2020
391
.. versionchanged:: 3.9
392
393
Updated to support the new union (``|``) operator from :pep:`584`, which
394
simply delegates to the underlying mapping.
395
Apr 15, 2012
Apr 15, 2012
396
.. describe:: key in proxy
397
398
Return ``True`` if the underlying mapping has a key *key*, else
399
``False``.
400
401
.. describe:: proxy[key]
402
403
Return the item of the underlying mapping with key *key*. Raises a
404
:exc:`KeyError` if *key* is not in the underlying mapping.
405
406
.. describe:: iter(proxy)
407
408
Return an iterator over the keys of the underlying mapping. This is a
409
shortcut for ``iter(proxy.keys())``.
410
411
.. describe:: len(proxy)
412
413
Return the number of items in the underlying mapping.
414
415
.. method:: copy()
416
417
Return a shallow copy of the underlying mapping.
418
419
.. method:: get(key[, default])
420
421
Return the value for *key* if *key* is in the underlying mapping, else
422
*default*. If *default* is not given, it defaults to ``None``, so that
423
this method never raises a :exc:`KeyError`.
424
425
.. method:: items()
426
427
Return a new view of the underlying mapping's items (``(key, value)``
428
pairs).
429
430
.. method:: keys()
431
432
Return a new view of the underlying mapping's keys.
433
434
.. method:: values()
435
436
Return a new view of the underlying mapping's values.
437
May 8, 2020
May 8, 2020
438
.. describe:: reversed(proxy)
439
440
Return a reverse iterator over the keys of the underlying mapping.
441
442
.. versionadded:: 3.9
443
Jun 28, 2022
Jun 28, 2022
444
.. describe:: hash(proxy)
445
446
Return a hash of the underlying mapping.
447
448
.. versionadded:: 3.12
449
Sep 25, 2023
Sep 25, 2023
450
.. class:: CapsuleType
451
452
The type of :ref:`capsule objects <capsules>`.
453
454
.. versionadded:: 3.13
455
Apr 15, 2012
Apr 15, 2012
456
Feb 25, 2014
Feb 25, 2014
457
Additional Utility Classes and Functions
458
----------------------------------------
459
Jun 3, 2012
Jun 3, 2012
460
.. class:: SimpleNamespace
461
462
A simple :class:`object` subclass that provides attribute access to its
463
namespace, as well as a meaningful repr.
464
Apr 24, 2024
Apr 24, 2024
465
Unlike :class:`object`, with :class:`!SimpleNamespace` you can add and remove
466
attributes.
467
468
:py:class:`SimpleNamespace` objects may be initialized
469
in the same way as :class:`dict`: either with keyword arguments,
470
with a single positional argument, or with both.
471
When initialized with keyword arguments,
472
those are directly added to the underlying namespace.
473
Alternatively, when initialized with a positional argument,
474
the underlying namespace will be updated with key-value pairs
475
from that argument (either a mapping object or
476
an :term:`iterable` object producing key-value pairs).
477
All such keys must be strings.
Jun 3, 2012
Jun 3, 2012
478
479
The type is roughly equivalent to the following code::
480
481
class SimpleNamespace:
Apr 24, 2024
Apr 24, 2024
482
def __init__(self, mapping_or_iterable=(), /, **kwargs):
483
self.__dict__.update(mapping_or_iterable)
Jun 3, 2012
Jun 3, 2012
484
self.__dict__.update(kwargs)
May 10, 2016
May 10, 2016
485
Jun 3, 2012
Jun 3, 2012
486
def __repr__(self):
May 16, 2020
May 16, 2020
487
items = (f"{k}={v!r}" for k, v in self.__dict__.items())
Jun 3, 2012
Jun 3, 2012
488
return "{}({})".format(type(self).__name__, ", ".join(items))
May 10, 2016
May 10, 2016
489
Feb 16, 2013
Feb 16, 2013
490
def __eq__(self, other):
Nov 13, 2020
Nov 13, 2020
491
if isinstance(self, SimpleNamespace) and isinstance(other, SimpleNamespace):
492
return self.__dict__ == other.__dict__
493
return NotImplemented
Jun 3, 2012
Jun 3, 2012
494
495
``SimpleNamespace`` may be useful as a replacement for ``class NS: pass``.
496
However, for a structured record type use :func:`~collections.namedtuple`
497
instead.
498
Sep 10, 2023
Sep 10, 2023
499
:class:`!SimpleNamespace` objects are supported by :func:`copy.replace`.
500
Jun 3, 2012
Jun 3, 2012
501
.. versionadded:: 3.3
Feb 25, 2014
Feb 25, 2014
502
May 16, 2020
May 16, 2020
503
.. versionchanged:: 3.9
504
Attribute order in the repr changed from alphabetical to insertion (like
505
``dict``).
Feb 25, 2014
Feb 25, 2014
506
Apr 24, 2024
Apr 24, 2024
507
.. versionchanged:: 3.13
508
Added support for an optional positional argument.
509
Feb 25, 2014
Feb 25, 2014
510
.. function:: DynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None)
511
512
Route attribute access on a class to __getattr__.
513
514
This is a descriptor, used to define attributes that act differently when
515
accessed through an instance and through a class. Instance access remains
516
normal, but access to an attribute through a class will be routed to the
517
class's __getattr__ method; this is done by raising AttributeError.
518
519
This allows one to have properties active on an instance, and have virtual
May 10, 2020
May 10, 2020
520
attributes on the class with the same name (see :class:`enum.Enum` for an example).
Feb 25, 2014
Feb 25, 2014
521
522
.. versionadded:: 3.4
May 21, 2015
May 21, 2015
523
524
Jun 24, 2015
Jun 24, 2015
525
Coroutine Utility Functions
526
---------------------------
May 21, 2015
May 21, 2015
527
528
.. function:: coroutine(gen_func)
529
Jun 24, 2015
Jun 24, 2015
530
This function transforms a :term:`generator` function into a
531
:term:`coroutine function` which returns a generator-based coroutine.
532
The generator-based coroutine is still a :term:`generator iterator`,
533
but is also considered to be a :term:`coroutine` object and is
534
:term:`awaitable`. However, it may not necessarily implement
Feb 27, 2023
Feb 27, 2023
535
the :meth:`~object.__await__` method.
May 21, 2015
May 21, 2015
536
Jun 24, 2015
Jun 24, 2015
537
If *gen_func* is a generator function, it will be modified in-place.
538
539
If *gen_func* is not a generator function, it will be wrapped. If it
540
returns an instance of :class:`collections.abc.Generator`, the instance
541
will be wrapped in an *awaitable* proxy object. All other types
542
of objects will be returned as is.
May 21, 2015
May 21, 2015
543
544
.. versionadded:: 3.5