summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2022-03-25 22:26:23 (GMT)
committerGitHub <noreply@github.com>2022-03-25 22:26:23 (GMT)
commitbad6ffaa64eecd33f4320ca31b1201b25cd8fc91 (patch)
tree28413f729dde37eb2d912a881efdaae5eab88744
parentd03acd7270d66ddb8e987f9743405147ecc15087 (diff)
downloadcpython-bad6ffaa64eecd33f4320ca31b1201b25cd8fc91.zip
cpython-bad6ffaa64eecd33f4320ca31b1201b25cd8fc91.tar.gz
cpython-bad6ffaa64eecd33f4320ca31b1201b25cd8fc91.tar.bz2
bpo-47062: Rename factory argument to loop_factory (GH-32113)
-rw-r--r--Doc/library/asyncio-runner.rst4
-rw-r--r--Lib/asyncio/runners.py10
-rw-r--r--Lib/test/test_asyncio/test_runners.py2
3 files changed, 8 insertions, 8 deletions
diff --git a/Doc/library/asyncio-runner.rst b/Doc/library/asyncio-runner.rst
index 2f4de9e..31becf1 100644
--- a/Doc/library/asyncio-runner.rst
+++ b/Doc/library/asyncio-runner.rst
@@ -62,7 +62,7 @@ Running an asyncio Program
Runner context manager
======================
-.. class:: Runner(*, debug=None, factory=None)
+.. class:: Runner(*, debug=None, loop_factory=None)
A context manager that simplifies *multiple* async function calls in the same
context.
@@ -74,7 +74,7 @@ Runner context manager
debug mode explicitly. ``None`` is used to respect the global
:ref:`asyncio-debug-mode` settings.
- *factory* could be used for overriding the loop creation.
+ *loop_factory* could be used for overriding the loop creation.
:func:`asyncio.new_event_loop` is used if ``None``.
Basically, :func:`asyncio.run()` example can be rewritten with the runner usage::
diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py
index 975509c..768a403 100644
--- a/Lib/asyncio/runners.py
+++ b/Lib/asyncio/runners.py
@@ -21,7 +21,7 @@ class Runner:
and properly finalizes the loop at the context manager exit.
If debug is True, the event loop will be run in debug mode.
- If factory is passed, it is used for new event loop creation.
+ If loop_factory is passed, it is used for new event loop creation.
asyncio.run(main(), debug=True)
@@ -41,10 +41,10 @@ class Runner:
# Note: the class is final, it is not intended for inheritance.
- def __init__(self, *, debug=None, factory=None):
+ def __init__(self, *, debug=None, loop_factory=None):
self._state = _State.CREATED
self._debug = debug
- self._factory = factory
+ self._loop_factory = loop_factory
self._loop = None
self._context = None
@@ -96,10 +96,10 @@ class Runner:
raise RuntimeError("Runner is closed")
if self._state is _State.INITIALIZED:
return
- if self._factory is None:
+ if self._loop_factory is None:
self._loop = events.new_event_loop()
else:
- self._loop = self._factory()
+ self._loop = self._loop_factory()
if self._debug is not None:
self._loop.set_debug(self._debug)
self._context = contextvars.copy_context()
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py
index c0bd1a2..94f2679 100644
--- a/Lib/test/test_asyncio/test_runners.py
+++ b/Lib/test/test_asyncio/test_runners.py
@@ -201,7 +201,7 @@ class RunnerTests(BaseTest):
def test_custom_factory(self):
loop = mock.Mock()
- with asyncio.Runner(factory=lambda: loop) as runner:
+ with asyncio.Runner(loop_factory=lambda: loop) as runner:
self.assertIs(runner.get_loop(), loop)
def test_run(self):