From 2f8ba138b5f7e8c3eb3e90cc5826852429ec65bd Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Tue, 27 Aug 2024 17:05:45 -0400 Subject: [PATCH] lazily call _default_version; it can be quite slow to call so often. --- cyclopts/core.py | 2 +- tests/test_app_name_derivation.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cyclopts/core.py b/cyclopts/core.py index b74c9179..089fce40 100644 --- a/cyclopts/core.py +++ b/cyclopts/core.py @@ -203,7 +203,7 @@ class App: kw_only=True, ) - version: Union[None, str, Callable[..., str]] = field(factory=_default_version, kw_only=True) + version: Union[None, str, Callable[..., str]] = field(default=_default_version, kw_only=True) # This can ONLY ever be a Tuple[str, ...] _version_flags: Union[str, Iterable[str]] = field( default=["--version"], diff --git a/tests/test_app_name_derivation.py b/tests/test_app_name_derivation.py index e8df130a..4fb4df7f 100644 --- a/tests/test_app_name_derivation.py +++ b/tests/test_app_name_derivation.py @@ -12,13 +12,12 @@ def test_app_name_derivation_main_module(mocker, mock_get_root_module_name): mocker.patch("cyclopts.core.sys.argv", ["__main__.py"]) app = App() - mock_get_root_module_name.assert_called() assert app.name == ("mock_module_name",) + mock_get_root_module_name.assert_called() -def test_app_name_derivation_not_main_module(mocker, mock_get_root_module_name): +def test_app_name_derivation_not_main_module(mocker): mocker.patch("cyclopts.core.sys.argv", ["my-script.py"]) app = App() - mock_get_root_module_name.assert_called() assert app.name == ("my-script.py",)