Skip to content

bpo-47062: Rename factory argument to loop_factory #32113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/asyncio-runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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::
Expand Down
10 changes: 5 additions & 5 deletions Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -96,10 +96,10 @@ def _lazy_init(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_debug(self):

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):
Expand Down