8000 bpo-47062: Rename factory argument to loop_factory (GH-32113) · python/cpython@bad6ffa · GitHub
[go: up one dir, main page]

Skip to content

Commit bad6ffa

Browse files
authored
bpo-47062: Rename factory argument to loop_factory (GH-32113)
1 parent d03acd7 commit bad6ffa

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Doc/library/asyncio-runner.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Running an asyncio Program
6262
Runner context manager
6363
======================
6464

65-
.. class:: Runner(*, debug=None, factory=None)
65+
.. class:: Runner(*, debug=None, loop_factory=None)
6666

6767
A context manager that simplifies *multiple* async function calls in the same
6868
context.
@@ -74,7 +74,7 @@ Runner context manager
7474
debug mode explicitly. ``None`` is used to respect the global
7575
:ref:`asyncio-debug-mode` settings.
7676

77-
*factory* could be used for overriding the loop creation.
77+
*loop_factory* could be used for overriding the loop creation.
7878
:func:`asyncio.new_event_loop` is used if ``None``.
7979

8080
Basically, :func:`asyncio.run()` example can be rewritten with the runner usage::

Lib/asyncio/runners.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Runner:
2121
and properly finalizes the loop at the context manager exit.
2222
2323
If debug is True, the event loop will be run in debug mode.
24-
If factory is passed, it is used for new event loop creation.
24+
If loop_factory is passed, it is used for new event loop creation.
2525
2626
asyncio.run(main(), debug=True)
2727
@@ -41,10 +41,10 @@ class Runner:
4141

4242
# Note: the class is final, it is not intended for inheritance.
4343

44-
def __init__(self, *, debug=None, factory=None):
44+
def __init__(self, *, debug=None, loop_factory=None):
4545
self._state = _State.CREATED
4646
self._debug = debug
47-
self._factory = factory
47+
self._loop_factory = loop_factory
4848
self._loop = None
4949
self._context = None
5050

@@ -96,10 +96,10 @@ def _lazy_init(self):
9696
raise RuntimeError("Runner is closed")
9797
if self._state is _State.INITIALIZED:
9898
return
99-
if self._factory is None:
99+
if self._loop_factory is None:
100100
self._loop = events.new_event_loop()
101101
else:
102-
self._loop = self._factory()
102+
self._loop = self._loop_factory()
103103
if self._debug is not None:
104104
self._loop.set_debug(self._debug)
105105
self._context = contextvars.copy_context()

Lib/test/test_asyncio/test_runners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_debug(self):
201201

202202
def test_custom_factory(self):
203203
loop = mock.Mock()
204-
with asyncio.Runner(factory=lambda: loop) as runner:
204+
with asyncio.Runner(loop_factory=lambda: loop) as runner:
205205
self.assertIs(runner.get_loop(), loop)
206206

207207
def test_run(self):

0 commit comments

Comments
 (0)
0