summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/coroutines.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/asyncio/coroutines.py')
-rw-r--r--Lib/asyncio/coroutines.py43
1 files changed, 18 insertions, 25 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index 7d2ca05..d7e6b4c 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -1,9 +1,7 @@
-__all__ = ['coroutine',
- 'iscoroutinefunction', 'iscoroutine']
+__all__ = 'coroutine', 'iscoroutinefunction', 'iscoroutine'
import functools
import inspect
-import opcode
import os
import sys
import traceback
@@ -27,9 +25,8 @@ def _is_debug_mode():
# before you define your coroutines. A downside of using this feature
# is that tracebacks show entries for the CoroWrapper.__next__ method
# when _DEBUG is true.
- return (sys.flags.dev_mode
- or (not sys.flags.ignore_environment
- and bool(os.environ.get('PYTHONASYNCIODEBUG'))))
+ return sys.flags.dev_mode or (not sys.flags.ignore_environment and
+ bool(os.environ.get('PYTHONASYNCIODEBUG')))
_DEBUG = _is_debug_mode()
@@ -58,8 +55,9 @@ class CoroWrapper:
coro_repr = _format_coroutine(self)
if self._source_traceback:
frame = self._source_traceback[-1]
- coro_repr += ', created at %s:%s' % (frame[0], frame[1])
- return '<%s %s>' % (self.__class__.__name__, coro_repr)
+ coro_repr += f', created at {frame[0]}:{frame[1]}'
+
+ return f'<{self.__class__.__name__} {coro_repr}>'
def __iter__(self):
return self
@@ -92,8 +90,8 @@ class CoroWrapper:
cr_await = getattr(self.gen, 'cr_await', None)
if cr_await is not None:
raise RuntimeError(
- "Cannot await on coroutine {!r} while it's "
- "awaiting for {!r}".format(self.gen, cr_await))
+ f"Cannot await on coroutine {self.gen!r} while it's "
+ f"awaiting for {cr_await!r}")
return self
@property
@@ -123,7 +121,7 @@ class CoroWrapper:
if frame is None:
frame = getattr(gen, 'cr_frame', None)
if frame is not None and frame.f_lasti == -1:
- msg = '%r was never yielded from' % self
+ msg = f'{self!r} was never yielded from'
tb = getattr(self, '_source_traceback', ())
if tb:
tb = ''.join(traceback.format_list(tb))
@@ -154,11 +152,10 @@ def coroutine(func):
def coro(*args, **kw):
res = func(*args, **kw)
if (base_futures.isfuture(res) or inspect.isgenerator(res) or
- isinstance(res, CoroWrapper)):
+ isinstance(res, CoroWrapper)):
res = yield from res
else:
- # If 'func' returns an Awaitable (new in 3.5) we
- # want to run it.
+ # If 'res' is an awaitable, run it.
try:
await_meth = res.__await__
except AttributeError:
@@ -219,7 +216,7 @@ def _format_coroutine(coro):
coro_name = getattr(
coro, '__qualname__',
getattr(coro, '__name__', type(coro).__name__))
- coro_name = '{}()'.format(coro_name)
+ coro_name = f'{coro_name}()'
running = False
try:
@@ -231,7 +228,7 @@ def _format_coroutine(coro):
pass
if running:
- return '{} running'.format(coro_name)
+ return f'{coro_name} running'
else:
return coro_name
@@ -240,7 +237,7 @@ def _format_coroutine(coro):
func = coro.func
coro_name = coro.__qualname__
if coro_name is not None:
- coro_name = '{}()'.format(coro_name)
+ coro_name = f'{coro_name}()'
else:
func = coro
@@ -266,18 +263,14 @@ def _format_coroutine(coro):
if source is not None:
filename, lineno = source
if coro_frame is None:
- coro_repr = ('%s done, defined at %s:%s'
- % (coro_name, filename, lineno))
+ coro_repr = f'{coro_name} done, defined at {filename}:{lineno}'
else:
- coro_repr = ('%s running, defined at %s:%s'
- % (coro_name, filename, lineno))
+ coro_repr = f'{coro_name} running, defined at {filename}:{lineno}'
elif coro_frame is not None:
lineno = coro_frame.f_lineno
- coro_repr = ('%s running at %s:%s'
- % (coro_name, filename, lineno))
+ coro_repr = f'{coro_name} running at {filename}:{lineno}'
else:
lineno = coro_code.co_firstlineno
- coro_repr = ('%s done, defined at %s:%s'
- % (coro_name, filename, lineno))
+ coro_repr = f'{coro_name} done, defined at {filename}:{lineno}'
return coro_repr