From ad7832e594fc41aa9afbbaf2555931c9effaec67 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 15 May 2025 12:27:21 -0700 Subject: [PATCH 1/7] add type annotation for one file --- tests/playwright/shiny/components/chat/shiny_output/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/playwright/shiny/components/chat/shiny_output/app.py b/tests/playwright/shiny/components/chat/shiny_output/app.py index 0fe8b8f3a..345c1d05c 100644 --- a/tests/playwright/shiny/components/chat/shiny_output/app.py +++ b/tests/playwright/shiny/components/chat/shiny_output/app.py @@ -1,6 +1,7 @@ import ipyleaflet as ipyl # pyright: ignore[reportMissingTypeStubs] import pandas as pd import plotly.express as px # pyright: ignore[reportMissingTypeStubs] +from plotly.graph_objs import Figure from shinywidgets import render_plotly, render_widget from shiny import reactive, render @@ -55,7 +56,7 @@ async def _(): with ui.hold() as plot_ui: @render_plotly - def plot(): + def plot() -> Figure: dat = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]}) return px.scatter(dat, x="x", y="y") # pyright: ignore[reportUnknownMemberType] From 3fef48aeddf0f796b127d93b636212ff21d7ed28 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 15 May 2025 12:39:14 -0700 Subject: [PATCH 2/7] add plotly typing stub --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 215ef4cb4..341160228 100644 --- a/Makefile +++ b/Makefile @@ -74,8 +74,11 @@ typings/matplotlib/__init__.pyi: git clone --depth 1 https://github.com/microsoft/python-type-stubs typings/python-type-stubs mv typings/python-type-stubs/stubs/matplotlib typings/ rm -rf typings/python-type-stubs +typings/plotly: + @echo "Creating plotly stubs" + pyright --createstub plotly -pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/matplotlib/__init__.pyi +pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/plotly typings/matplotlib/__init__.pyi check: check-format check-lint check-types check-tests ## check code, style, types, and test (basic CI) check-fix: format check-lint check-types check-tests ## check and format code, style, types, and test From 2767868cd29f52bc5a498708413bb90baf3e0188 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 15 May 2025 12:47:26 -0700 Subject: [PATCH 3/7] use correct imports --- tests/playwright/shiny/components/chat/shiny_output/app.py | 2 +- tests/playwright/shiny/components/data_frame/edit/app.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/playwright/shiny/components/chat/shiny_output/app.py b/tests/playwright/shiny/components/chat/shiny_output/app.py index 345c1d05c..a0553731d 100644 --- a/tests/playwright/shiny/components/chat/shiny_output/app.py +++ b/tests/playwright/shiny/components/chat/shiny_output/app.py @@ -1,7 +1,7 @@ import ipyleaflet as ipyl # pyright: ignore[reportMissingTypeStubs] import pandas as pd import plotly.express as px # pyright: ignore[reportMissingTypeStubs] -from plotly.graph_objs import Figure +from plotly.graph_objs._figure import Figure from shinywidgets import render_plotly, render_widget from shiny import reactive, render diff --git a/tests/playwright/shiny/components/data_frame/edit/app.py b/tests/playwright/shiny/components/data_frame/edit/app.py index 2f8707e39..32fa513f9 100644 --- a/tests/playwright/shiny/components/data_frame/edit/app.py +++ b/tests/playwright/shiny/components/data_frame/edit/app.py @@ -17,6 +17,7 @@ import great_tables as gt import palmerpenguins # pyright: ignore[reportMissingTypeStubs] import polars as pl +from plotly.graph_objs._figure import Figure from shiny import App, Inputs, Outputs, Session, module, reactive, render, req, ui from shiny.render import CellPatch @@ -264,7 +265,7 @@ def df_styles_fn(data: pd.DataFrame) -> list[StyleInfo]: # from shiny import reactive @render_widget - def country_detail_pop(): + def country_detail_pop() -> Figure: import plotly.express as px return px.line( From 1bf77183f0f28b9cb354728b90f908b31613bda3 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 15 May 2025 13:23:43 -0700 Subject: [PATCH 4/7] use explicit return type --- tests/playwright/shiny/components/data_frame/edit/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/playwright/shiny/components/data_frame/edit/app.py b/tests/playwright/shiny/components/data_frame/edit/app.py index 32fa513f9..3e1a2412b 100644 --- a/tests/playwright/shiny/components/data_frame/edit/app.py +++ b/tests/playwright/shiny/components/data_frame/edit/app.py @@ -269,6 +269,7 @@ def country_detail_pop() -> Figure: import plotly.express as px return px.line( + fig: Figure = px.line( px.data.gapminder(), x="year", y="lifeExp", @@ -276,6 +277,8 @@ def country_detail_pop() -> Figure: title="Population Over Time", ) + return fig + @summary_data.set_patch_fn def upgrade_patch( *, From e1cf2e7a2e34fe4ebccc1e08d2319a656a516825 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Thu, 15 May 2025 13:27:43 -0700 Subject: [PATCH 5/7] remove erroneous line --- tests/playwright/shiny/components/data_frame/edit/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/playwright/shiny/components/data_frame/edit/app.py b/tests/playwright/shiny/components/data_frame/edit/app.py index 3e1a2412b..98c44233a 100644 --- a/tests/playwright/shiny/components/data_frame/edit/app.py +++ b/tests/playwright/shiny/components/data_frame/edit/app.py @@ -268,7 +268,6 @@ def df_styles_fn(data: pd.DataFrame) -> list[StyleInfo]: def country_detail_pop() -> Figure: import plotly.express as px - return px.line( fig: Figure = px.line( px.data.gapminder(), x="year", From fcb118a122be30e66def643115fcb3c569575ada Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 16 May 2025 06:26:09 -0700 Subject: [PATCH 6/7] adding ignore to pyright errors within apps --- Makefile | 6 +----- .../shiny/components/chat/shiny_output/app.py | 7 ++++--- .../shiny/components/data_frame/edit/app.py | 12 ++++-------- .../shiny/components/data_frame/html_columns/app.py | 6 +++--- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 341160228..a519ff3d4 100644 --- a/Makefile +++ b/Makefile @@ -74,11 +74,7 @@ typings/matplotlib/__init__.pyi: git clone --depth 1 https://github.com/microsoft/python-type-stubs typings/python-type-stubs mv typings/python-type-stubs/stubs/matplotlib typings/ rm -rf typings/python-type-stubs -typings/plotly: - @echo "Creating plotly stubs" - pyright --createstub plotly - -pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/plotly typings/matplotlib/__init__.pyi +pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/matplotlib/__init__.pyi check: check-format check-lint check-types check-tests ## check code, style, types, and test (basic CI) check-fix: format check-lint check-types check-tests ## check and format code, style, types, and test diff --git a/tests/playwright/shiny/components/chat/shiny_output/app.py b/tests/playwright/shiny/components/chat/shiny_output/app.py index a0553731d..b9284109c 100644 --- a/tests/playwright/shiny/components/chat/shiny_output/app.py +++ b/tests/playwright/shiny/components/chat/shiny_output/app.py @@ -1,7 +1,6 @@ import ipyleaflet as ipyl # pyright: ignore[reportMissingTypeStubs] import pandas as pd import plotly.express as px # pyright: ignore[reportMissingTypeStubs] -from plotly.graph_objs._figure import Figure from shinywidgets import render_plotly, render_widget from shiny import reactive, render @@ -56,9 +55,11 @@ async def _(): with ui.hold() as plot_ui: @render_plotly - def plot() -> Figure: + def plot(): # pyright: ignore[reportUnknownReturnType,reportUnknownParameterType] dat = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]}) - return px.scatter(dat, x="x", y="y") # pyright: ignore[reportUnknownMemberType] + return px.scatter( # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType] + dat, x="x", y="y" + ) @reactive.effect diff --git a/tests/playwright/shiny/components/data_frame/edit/app.py b/tests/playwright/shiny/components/data_frame/edit/app.py index 98c44233a..c0b5a9549 100644 --- a/tests/playwright/shiny/components/data_frame/edit/app.py +++ b/tests/playwright/shiny/components/data_frame/edit/app.py @@ -17,7 +17,6 @@ import great_tables as gt import palmerpenguins # pyright: ignore[reportMissingTypeStubs] import polars as pl -from plotly.graph_objs._figure import Figure from shiny import App, Inputs, Outputs, Session, module, reactive, render, req, ui from shiny.render import CellPatch @@ -262,22 +261,19 @@ def df_styles_fn(data: pd.DataFrame) -> list[StyleInfo]: # print(summary_data._type_hints()) from shinywidgets import render_widget - # from shiny import reactive - @render_widget - def country_detail_pop() -> Figure: + def country_detail_pop(): # pyright: ignore[reportUnknownParameterType] import plotly.express as px - fig: Figure = px.line( - px.data.gapminder(), + # Create the figure explicitly + return px.line( + px.data.gapminder(), # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue] x="year", y="lifeExp", color="country", title="Population Over Time", ) - return fig - @summary_data.set_patch_fn def upgrade_patch( *, diff --git a/tests/playwright/shiny/components/data_frame/html_columns/app.py b/tests/playwright/shiny/components/data_frame/html_columns/app.py index 45f5f8dbc..d6764e31d 100644 --- a/tests/playwright/shiny/components/data_frame/html_columns/app.py +++ b/tests/playwright/shiny/components/data_frame/html_columns/app.py @@ -33,10 +33,10 @@ def random_generator(): ) ) -studyName = ( - pd_penguins["studyName"] # pyright: ignore[reportUnknownVariableType] +studyName = ( # pyright: ignore[reportUnknownVariableType] + pd_penguins["studyName"] .copy() - .astype("object") + .astype("object") # pyright: ignore[reportUnknownMemberType] ) # Set the first value of the column to an html object so the column is treated as object by narwhals (not str) studyName[0] = htmlDep From 7f4427dd79b643129b726080c409d2fa37f2686d Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Fri, 16 May 2025 06:48:54 -0700 Subject: [PATCH 7/7] restore newline in makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a519ff3d4..215ef4cb4 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,7 @@ typings/matplotlib/__init__.pyi: git clone --depth 1 https://github.com/microsoft/python-type-stubs typings/python-type-stubs mv typings/python-type-stubs/stubs/matplotlib typings/ rm -rf typings/python-type-stubs + pyright-typings: typings/appdirs typings/folium typings/uvicorn typings/seaborn typings/matplotlib/__init__.pyi check: check-format check-lint check-types check-tests ## check code, style, types, and test (basic CI)