From 2cb193e8d61ec6f02e0729dfdbc9156874bd6114 Mon Sep 17 00:00:00 2001 From: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:08:37 +0100 Subject: [PATCH] improve app_src typing (#4324) --- benchmarks/test_benchmark_compile_pages.py | 4 ++-- reflex/testing.py | 4 ++-- tests/integration/test_background_task.py | 2 +- tests/integration/test_call_script.py | 2 +- tests/integration/test_client_storage.py | 2 +- tests/integration/test_component_state.py | 2 +- tests/integration/test_computed_vars.py | 2 +- tests/integration/test_connection_banner.py | 2 +- tests/integration/test_deploy_url.py | 2 +- tests/integration/test_dynamic_components.py | 2 +- tests/integration/test_dynamic_routes.py | 2 +- tests/integration/test_event_actions.py | 2 +- tests/integration/test_event_chain.py | 2 +- tests/integration/test_exception_handlers.py | 2 +- tests/integration/test_form_submit.py | 2 +- tests/integration/test_input.py | 2 +- tests/integration/test_lifespan.py | 2 +- tests/integration/test_login_flow.py | 2 +- tests/integration/test_media.py | 2 +- tests/integration/test_navigation.py | 2 +- tests/integration/test_server_side_event.py | 2 +- tests/integration/test_shared_state.py | 2 +- tests/integration/test_state_inheritance.py | 2 +- tests/integration/test_tailwind.py | 2 +- tests/integration/test_upload.py | 2 +- tests/integration/test_var_operations.py | 2 +- tests/integration/tests_playwright/test_stateless_app.py | 2 +- tests/integration/tests_playwright/test_table.py | 2 +- tests/test_node_version.py | 2 +- tests/units/test_testing.py | 2 +- 30 files changed, 32 insertions(+), 32 deletions(-) diff --git a/benchmarks/test_benchmark_compile_pages.py b/benchmarks/test_benchmark_compile_pages.py index f232eb627..292882b74 100644 --- a/benchmarks/test_benchmark_compile_pages.py +++ b/benchmarks/test_benchmark_compile_pages.py @@ -212,7 +212,7 @@ def app_with_one_page( """ root = tmp_path_factory.mktemp("app1") - yield AppHarness.create(root=root, app_source=AppWithOnePage) # type: ignore + yield AppHarness.create(root=root, app_source=AppWithOnePage) @pytest.fixture(scope="session") @@ -276,7 +276,7 @@ def app_with_thousand_pages( yield AppHarness.create( root=root, - app_source=functools.partial( # type: ignore + app_source=functools.partial( AppWithThousandPages, render_comp=render_multiple_pages, # type: ignore ), diff --git a/reflex/testing.py b/reflex/testing.py index bb7ead2d9..9ddb03504 100644 --- a/reflex/testing.py +++ b/reflex/testing.py @@ -118,7 +118,7 @@ class AppHarness: app_name: str app_source: Optional[ - types.FunctionType | types.ModuleType | str | functools.partial[Any] + Callable[[], None] | types.ModuleType | str | functools.partial[Any] ] app_path: pathlib.Path app_module_path: pathlib.Path @@ -138,7 +138,7 @@ class AppHarness: cls, root: pathlib.Path, app_source: Optional[ - types.FunctionType | types.ModuleType | str | functools.partial[Any] + Callable[[], None] | types.ModuleType | str | functools.partial[Any] ] = None, app_name: Optional[str] = None, ) -> "AppHarness": diff --git a/tests/integration/test_background_task.py b/tests/integration/test_background_task.py index 00cf83ea0..d7fe20824 100644 --- a/tests/integration/test_background_task.py +++ b/tests/integration/test_background_task.py @@ -190,7 +190,7 @@ def background_task( """ with AppHarness.create( root=tmp_path_factory.mktemp("background_task"), - app_source=BackgroundTask, # type: ignore + app_source=BackgroundTask, ) as harness: yield harness diff --git a/tests/integration/test_call_script.py b/tests/integration/test_call_script.py index a949dc451..71200221b 100644 --- a/tests/integration/test_call_script.py +++ b/tests/integration/test_call_script.py @@ -355,7 +355,7 @@ def call_script(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("call_script"), - app_source=CallScript, # type: ignore + app_source=CallScript, ) as harness: yield harness diff --git a/tests/integration/test_client_storage.py b/tests/integration/test_client_storage.py index ae66087e2..e8c95ab71 100644 --- a/tests/integration/test_client_storage.py +++ b/tests/integration/test_client_storage.py @@ -137,7 +137,7 @@ def client_side(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("client_side"), - app_source=ClientSide, # type: ignore + app_source=ClientSide, ) as harness: yield harness diff --git a/tests/integration/test_component_state.py b/tests/integration/test_component_state.py index f4a295d07..97624e7c5 100644 --- a/tests/integration/test_component_state.py +++ b/tests/integration/test_component_state.py @@ -115,7 +115,7 @@ def component_state_app(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=ComponentStateApp, # type: ignore + app_source=ComponentStateApp, ) as harness: yield harness diff --git a/tests/integration/test_computed_vars.py b/tests/integration/test_computed_vars.py index a39cb9e65..a41458173 100644 --- a/tests/integration/test_computed_vars.py +++ b/tests/integration/test_computed_vars.py @@ -125,7 +125,7 @@ def computed_vars( """ with AppHarness.create( root=tmp_path_factory.mktemp("computed_vars"), - app_source=ComputedVars, # type: ignore + app_source=ComputedVars, ) as harness: yield harness diff --git a/tests/integration/test_connection_banner.py b/tests/integration/test_connection_banner.py index 6921444b0..44187c8ba 100644 --- a/tests/integration/test_connection_banner.py +++ b/tests/integration/test_connection_banner.py @@ -52,7 +52,7 @@ def connection_banner(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=ConnectionBanner, # type: ignore + app_source=ConnectionBanner, ) as harness: yield harness diff --git a/tests/integration/test_deploy_url.py b/tests/integration/test_deploy_url.py index f93e9db27..5c840d24d 100644 --- a/tests/integration/test_deploy_url.py +++ b/tests/integration/test_deploy_url.py @@ -44,7 +44,7 @@ def deploy_url_sample( """ with AppHarness.create( root=tmp_path_factory.mktemp("deploy_url_sample"), - app_source=DeployUrlSample, # type: ignore + app_source=DeployUrlSample, ) as harness: yield harness diff --git a/tests/integration/test_dynamic_components.py b/tests/integration/test_dynamic_components.py index aeebd10e9..6a68aa1a1 100644 --- a/tests/integration/test_dynamic_components.py +++ b/tests/integration/test_dynamic_components.py @@ -85,7 +85,7 @@ def dynamic_components(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("dynamic_components"), - app_source=DynamicComponents, # type: ignore + app_source=DynamicComponents, ) as harness: assert harness.app_instance is not None, "app is not running" yield harness diff --git a/tests/integration/test_dynamic_routes.py b/tests/integration/test_dynamic_routes.py index ffb4b1c3c..eed066696 100644 --- a/tests/integration/test_dynamic_routes.py +++ b/tests/integration/test_dynamic_routes.py @@ -155,7 +155,7 @@ def dynamic_route( with app_harness_env.create( root=tmp_path_factory.mktemp("dynamic_route"), app_name=f"dynamicroute_{app_harness_env.__name__.lower()}", - app_source=DynamicRoute, # type: ignore + app_source=DynamicRoute, ) as harness: yield harness diff --git a/tests/integration/test_event_actions.py b/tests/integration/test_event_actions.py index 58e26bf09..15f3c9877 100644 --- a/tests/integration/test_event_actions.py +++ b/tests/integration/test_event_actions.py @@ -172,7 +172,7 @@ def event_action(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("event_action"), - app_source=TestEventAction, # type: ignore + app_source=TestEventAction, ) as harness: yield harness diff --git a/tests/integration/test_event_chain.py b/tests/integration/test_event_chain.py index ea2d2191c..c4121ee94 100644 --- a/tests/integration/test_event_chain.py +++ b/tests/integration/test_event_chain.py @@ -277,7 +277,7 @@ def event_chain(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("event_chain"), - app_source=EventChain, # type: ignore + app_source=EventChain, ) as harness: yield harness diff --git a/tests/integration/test_exception_handlers.py b/tests/integration/test_exception_handlers.py index 00683c48b..e88b462ff 100644 --- a/tests/integration/test_exception_handlers.py +++ b/tests/integration/test_exception_handlers.py @@ -70,7 +70,7 @@ def test_app( with app_harness_env.create( root=tmp_path_factory.mktemp("test_app"), app_name=f"testapp_{app_harness_env.__name__.lower()}", - app_source=TestApp, # type: ignore + app_source=TestApp, ) as harness: yield harness diff --git a/tests/integration/test_form_submit.py b/tests/integration/test_form_submit.py index 3bfcf6e8c..ea8750595 100644 --- a/tests/integration/test_form_submit.py +++ b/tests/integration/test_form_submit.py @@ -159,7 +159,7 @@ def form_submit(request, tmp_path_factory) -> Generator[AppHarness, None, None]: param_id = request._pyfuncitem.callspec.id.replace("-", "_") with AppHarness.create( root=tmp_path_factory.mktemp("form_submit"), - app_source=request.param, # type: ignore + app_source=request.param, app_name=request.param.func.__name__ + f"_{param_id}", ) as harness: assert harness.app_instance is not None, "app is not running" diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index 4679104a4..c718749aa 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -63,7 +63,7 @@ def fully_controlled_input(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=FullyControlledInput, # type: ignore + app_source=FullyControlledInput, ) as harness: yield harness diff --git a/tests/integration/test_lifespan.py b/tests/integration/test_lifespan.py index 22c399c07..cb6c640ab 100644 --- a/tests/integration/test_lifespan.py +++ b/tests/integration/test_lifespan.py @@ -80,7 +80,7 @@ def lifespan_app(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=LifespanApp, # type: ignore + app_source=LifespanApp, ) as harness: yield harness diff --git a/tests/integration/test_login_flow.py b/tests/integration/test_login_flow.py index ecaade9cf..1938672a3 100644 --- a/tests/integration/test_login_flow.py +++ b/tests/integration/test_login_flow.py @@ -62,7 +62,7 @@ def login_sample(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("login_sample"), - app_source=LoginSample, # type: ignore + app_source=LoginSample, ) as harness: yield harness diff --git a/tests/integration/test_media.py b/tests/integration/test_media.py index c10f7102b..10af26591 100644 --- a/tests/integration/test_media.py +++ b/tests/integration/test_media.py @@ -84,7 +84,7 @@ def media_app(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=MediaApp, # type: ignore + app_source=MediaApp, ) as harness: yield harness diff --git a/tests/integration/test_navigation.py b/tests/integration/test_navigation.py index b4505ed1c..4e81e4155 100644 --- a/tests/integration/test_navigation.py +++ b/tests/integration/test_navigation.py @@ -52,7 +52,7 @@ def navigation_app(tmp_path) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path, - app_source=NavigationApp, # type: ignore + app_source=NavigationApp, ) as harness: yield harness diff --git a/tests/integration/test_server_side_event.py b/tests/integration/test_server_side_event.py index 7fd592d10..f04cc3beb 100644 --- a/tests/integration/test_server_side_event.py +++ b/tests/integration/test_server_side_event.py @@ -93,7 +93,7 @@ def server_side_event(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("server_side_event"), - app_source=ServerSideEvent, # type: ignore + app_source=ServerSideEvent, ) as harness: yield harness diff --git a/tests/integration/test_shared_state.py b/tests/integration/test_shared_state.py index 6f59c5142..410669381 100644 --- a/tests/integration/test_shared_state.py +++ b/tests/integration/test_shared_state.py @@ -39,7 +39,7 @@ def shared_state( """ with AppHarness.create( root=tmp_path_factory.mktemp("shared_state"), - app_source=SharedStateApp, # type: ignore + app_source=SharedStateApp, ) as harness: yield harness diff --git a/tests/integration/test_state_inheritance.py b/tests/integration/test_state_inheritance.py index a9f55d9a9..81512a67a 100644 --- a/tests/integration/test_state_inheritance.py +++ b/tests/integration/test_state_inheritance.py @@ -217,7 +217,7 @@ def state_inheritance( """ with AppHarness.create( root=tmp_path_factory.mktemp("state_inheritance"), - app_source=StateInheritance, # type: ignore + app_source=StateInheritance, ) as harness: yield harness diff --git a/tests/integration/test_tailwind.py b/tests/integration/test_tailwind.py index bda664a1c..eb0fde759 100644 --- a/tests/integration/test_tailwind.py +++ b/tests/integration/test_tailwind.py @@ -78,7 +78,7 @@ def tailwind_app(tmp_path, tailwind_disabled) -> Generator[AppHarness, None, Non """ with AppHarness.create( root=tmp_path, - app_source=functools.partial(TailwindApp, tailwind_disabled=tailwind_disabled), # type: ignore + app_source=functools.partial(TailwindApp, tailwind_disabled=tailwind_disabled), app_name="tailwind_disabled_app" if tailwind_disabled else "tailwind_app", ) as harness: yield harness diff --git a/tests/integration/test_upload.py b/tests/integration/test_upload.py index 602905b3e..fe8ebb4d7 100644 --- a/tests/integration/test_upload.py +++ b/tests/integration/test_upload.py @@ -133,7 +133,7 @@ def upload_file(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("upload_file"), - app_source=UploadFile, # type: ignore + app_source=UploadFile, ) as harness: yield harness diff --git a/tests/integration/test_var_operations.py b/tests/integration/test_var_operations.py index cae56e1a8..7a7c8328d 100644 --- a/tests/integration/test_var_operations.py +++ b/tests/integration/test_var_operations.py @@ -613,7 +613,7 @@ def var_operations(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("var_operations"), - app_source=VarOperations, # type: ignore + app_source=VarOperations, ) as harness: assert harness.app_instance is not None, "app is not running" yield harness diff --git a/tests/integration/tests_playwright/test_stateless_app.py b/tests/integration/tests_playwright/test_stateless_app.py index 129b69dc7..0c0b2959b 100644 --- a/tests/integration/tests_playwright/test_stateless_app.py +++ b/tests/integration/tests_playwright/test_stateless_app.py @@ -33,7 +33,7 @@ def stateless_app(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("stateless_app"), - app_source=StatelessApp, # type: ignore + app_source=StatelessApp, ) as harness: yield harness diff --git a/tests/integration/tests_playwright/test_table.py b/tests/integration/tests_playwright/test_table.py index 917247b89..0a39b197e 100644 --- a/tests/integration/tests_playwright/test_table.py +++ b/tests/integration/tests_playwright/test_table.py @@ -68,7 +68,7 @@ def table_app(tmp_path_factory) -> Generator[AppHarness, None, None]: """ with AppHarness.create( root=tmp_path_factory.mktemp("table"), - app_source=Table, # type: ignore + app_source=Table, ) as harness: assert harness.app_instance is not None, "app is not running" yield harness diff --git a/tests/test_node_version.py b/tests/test_node_version.py index 9555eb524..defba3d20 100644 --- a/tests/test_node_version.py +++ b/tests/test_node_version.py @@ -43,7 +43,7 @@ def node_version_app(tmp_path) -> Generator[AppHarness, Any, None]: """ with AppHarness.create( root=tmp_path, - app_source=TestNodeVersionApp, # type: ignore + app_source=TestNodeVersionApp, ) as harness: yield harness diff --git a/tests/units/test_testing.py b/tests/units/test_testing.py index b01709202..83a03ad83 100644 --- a/tests/units/test_testing.py +++ b/tests/units/test_testing.py @@ -29,7 +29,7 @@ def test_app_harness(tmp_path): with AppHarness.create( root=tmp_path, - app_source=BasicApp, # type: ignore + app_source=BasicApp, ) as harness: assert harness.app_instance is not None assert harness.backend is not None