-
-
Notifications
You must be signed in to change notification settings - Fork 37k
Expand file tree
/
Copy path_pybuiltins.py
More file actions
42 lines (32 loc) · 1.13 KB
/
Copy path_pybuiltins.py
File metadata and controls
42 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Builtins implemented in Python.
This module is frozen into the interpreter and imported during startup,
before the import system exists. The names listed in ``__all__`` are
copied into the ``builtins`` module.
"""
__all__ = ['anext']
_NOT_GIVEN = sentinel("_NOT_GIVEN")
def anext(async_iterator, default=_NOT_GIVEN, /):
"""Return the next item from the async iterator.
If default is given and the async iterator is exhausted,
it is returned instead of raising StopAsyncIteration.
"""
cls = type(async_iterator)
try:
# Looked up on the type, like the C slot am_anext.
anext_method = cls.__anext__
except AttributeError:
raise TypeError(
f"{cls.__name__!r} object is not an async iterator"
) from None
awaitable = anext_method(async_iterator)
if default is _NOT_GIVEN:
return awaitable
return _anext_with_default(awaitable, default)
async def _anext_with_default(awaitable, default):
try:
return await awaitable
except StopAsyncIteration:
return default
for _name in __all__:
globals()[_name].__module__ = 'builtins'
del _name