bpo-47062: Rename factory argument to loop_factory (GH-32113) · python/cpython@bad6ffa (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -62,7 +62,7 @@ Running an asyncio Program | ||
62 | 62 | Runner context manager |
63 | 63 | ====================== |
64 | 64 | |
65 | -.. class:: Runner(*, debug=None, factory=None) | |
65 | +.. class:: Runner(*, debug=None, loop_factory=None) | |
66 | 66 | |
67 | 67 | A context manager that simplifies *multiple* async function calls in the same |
68 | 68 | context. |
@@ -74,7 +74,7 @@ Runner context manager | ||
74 | 74 | debug mode explicitly. ``None`` is used to respect the global |
75 | 75 | :ref:`asyncio-debug-mode` settings. |
76 | 76 | |
77 | - *factory* could be used for overriding the loop creation. | |
77 | + *loop_factory* could be used for overriding the loop creation. | |
78 | 78 | :func:`asyncio.new_event_loop` is used if ``None``. |
79 | 79 | |
80 | 80 | Basically, :func:`asyncio.run()` example can be rewritten with the runner usage:: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,7 +21,7 @@ class Runner: | ||
21 | 21 | and properly finalizes the loop at the context manager exit. |
22 | 22 | |
23 | 23 | 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. | |
25 | 25 | |
26 | 26 | asyncio.run(main(), debug=True) |
27 | 27 | |
@@ -41,10 +41,10 @@ class Runner: | ||
41 | 41 | |
42 | 42 | # Note: the class is final, it is not intended for inheritance. |
43 | 43 | |
44 | -def __init__(self, *, debug=None, factory=None): | |
44 | +def __init__(self, *, debug=None, loop_factory=None): | |
45 | 45 | self._state = _State.CREATED |
46 | 46 | self._debug = debug |
47 | -self._factory = factory | |
47 | +self._loop_factory = loop_factory | |
48 | 48 | self._loop = None |
49 | 49 | self._context = None |
50 | 50 | |
@@ -96,10 +96,10 @@ def _lazy_init(self): | ||
96 | 96 | raise RuntimeError("Runner is closed") |
97 | 97 | if self._state is _State.INITIALIZED: |
98 | 98 | return |
99 | -if self._factory is None: | |
99 | +if self._loop_factory is None: | |
100 | 100 | self._loop = events.new_event_loop() |
101 | 101 | else: |
102 | -self._loop = self._factory() | |
102 | +self._loop = self._loop_factory() | |
103 | 103 | if self._debug is not None: |
104 | 104 | self._loop.set_debug(self._debug) |
105 | 105 | self._context = contextvars.copy_context() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -201,7 +201,7 @@ def test_debug(self): | ||
201 | 201 | |
202 | 202 | def test_custom_factory(self): |
203 | 203 | loop = mock.Mock() |
204 | -with asyncio.Runner(factory=lambda: loop) as runner: | |
204 | +with asyncio.Runner(loop_factory=lambda: loop) as runner: | |
205 | 205 | self.assertIs(runner.get_loop(), loop) |
206 | 206 | |
207 | 207 | def test_run(self): |