Skip to content

Commit 3d0d46a

Browse files
authored
Raise an exception when calling removed Config.setup_event_loop() (#2709)
1 parent ad9e5b9 commit 3d0d46a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,11 @@ def test_custom_loop__not_importable_custom_loop_setup_function(caplog: pytest.L
585585
'Error loading custom loop setup function. Attribute "non_existing_setup_function" not found in module "tests.test_config".' # noqa: E501
586586
== error_messages.pop(0)
587587
)
588+
589+
590+
def test_setup_event_loop_is_removed(caplog: pytest.LogCaptureFixture) -> None:
591+
config = Config(app=asgi_app)
592+
with pytest.raises(
593+
AttributeError, match="The `setup_event_loop` method was replaced by `get_loop_factory` in uvicorn 0.36.0."
594+
):
595+
config.setup_event_loop()

uvicorn/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,16 @@ def load(self) -> None:
473473

474474
self.loaded = True
475475

476+
def setup_event_loop(self) -> None:
477+
raise AttributeError(
478+
"The `setup_event_loop` method was replaced by `get_loop_factory` in uvicorn 0.36.0.\n"
479+
"None of those methods are supposed to be used directly. If you are doing it, please let me know here: "
480+
"https://github.com/Kludex/uvicorn/discussions/2706. Thank you, and sorry for the inconvenience."
481+
)
482+
476483
def get_loop_factory(self) -> Callable[[], asyncio.AbstractEventLoop] | None:
477484
if self.loop in LOOP_FACTORIES:
478-
loop_factory: Callable | None = import_from_string(LOOP_FACTORIES[self.loop])
485+
loop_factory: Callable[..., Any] | None = import_from_string(LOOP_FACTORIES[self.loop])
479486
else:
480487
try:
481488
return import_from_string(self.loop)

0 commit comments

Comments
 (0)