From 60f9406dffe624528a52358ec238ce3b2c5f6201 Mon Sep 17 00:00:00 2001 From: Justus Schock <12886177+justusschock@users.noreply.github.com> Date: Tue, 17 Jan 2023 15:13:05 +0100 Subject: [PATCH] rename app `_exit` 2/2 (#16398) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> --- src/lightning_app/core/flow.py | 19 ++++++++++++++++++- tests/tests_app/core/test_lightning_flow.py | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index fe1a5f0ea8dab..6e2b43b3a5215 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -1,4 +1,5 @@ import inspect +import warnings from copy import deepcopy from datetime import datetime from types import FrameType @@ -367,11 +368,27 @@ def set_state(self, provided_state: Dict, recurse: bool = True) -> None: getattr(self, structure).set_state(state) def stop(self, end_msg: str = "") -> None: - """Private method used to exit the application.""" + """Method used to exit the application.""" if end_msg: print(end_msg) raise ExitAppException + def _exit(self, end_msg: str = "") -> None: + """Used to exit the application. + + Private method. + + .. deprecated:: 1.9.0 + This function is deprecated and will be removed in 2.0.0. Use :meth:`stop` instead. + """ + warnings.warn( + DeprecationWarning( + "This function is deprecated and will be removed in 2.0.0. Use `LightningFlow.stop` instead." + ) + ) + + return self.stop(end_msg=end_msg) + @staticmethod def _is_state_attribute(name: str) -> bool: """Every public attribute is part of the state by default and all protected (prefixed by '_') or private diff --git a/tests/tests_app/core/test_lightning_flow.py b/tests/tests_app/core/test_lightning_flow.py index 8b1302a9b4a89..476ad491dc01a 100644 --- a/tests/tests_app/core/test_lightning_flow.py +++ b/tests/tests_app/core/test_lightning_flow.py @@ -954,3 +954,9 @@ def run(self): assert len(v.component_names) == 1 assert v.component_names[0][:-1] in ("root.w_list.", "root.w_dict.") assert v.component_names[0][-1].isdigit() + + +def test_deprecation_warning_exit(): + with pytest.raises(ExitAppException): + with pytest.warns(DeprecationWarning, match="*Use LightningFlow.stop instead"): + RootFlowReady()._exit()