From 17bcdf910e434629204b5bcbc56a3550818821f1 Mon Sep 17 00:00:00 2001 From: cross32768 Date: Fri, 30 Jun 2023 11:00:27 +0900 Subject: [PATCH] Fix some linter problems --- optuna_dashboard/_streamlit_helper.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/optuna_dashboard/_streamlit_helper.py b/optuna_dashboard/_streamlit_helper.py index 2867673c..32e2f705 100644 --- a/optuna_dashboard/_streamlit_helper.py +++ b/optuna_dashboard/_streamlit_helper.py @@ -44,8 +44,6 @@ def render_user_attr_form_widgets(study: optuna.Study, trial: FrozenTrial) -> No ): raise ValueError("'output_type' should be 'user_attr'.") - st.write("## Objective Form Widgets") - widgets = form_widgets_dict["widgets"] values = [] with st.form("user_input", clear_on_submit=False): @@ -54,14 +52,14 @@ def render_user_attr_form_widgets(study: optuna.Study, trial: FrozenTrial) -> No value = st.radio( widget["description"], widget["values"], - format_func=lambda choice: widget["choices"][ + format_func=lambda choice, widget=widget: widget["choices"][ widget["values"].index(choice) - ], # noqa: B023 + ], horizontal=True, ) values.append(value) elif widget["type"] == "slider": - # NOTE: It is difficult to reflect "labels. + # NOTE: It is difficult to reflect "labels". value = st.slider( widget["description"], min_value=widget["min"], @@ -70,7 +68,8 @@ def render_user_attr_form_widgets(study: optuna.Study, trial: FrozenTrial) -> No ) values.append(value) elif widget["type"] == "text": - # TODO (kaitos): It is better to consider "optional". + # TODO (kaitos): Resolve that current implementation ignores "optional" + # (always optional on streamlit) value = st.text_input(widget["description"]) values.append(value) else: @@ -79,8 +78,11 @@ def render_user_attr_form_widgets(study: optuna.Study, trial: FrozenTrial) -> No if submitted: for widget, value in zip(widgets, values): + # "type: ignore" is required because "UserAttrRefJSON" has no key "user_attr_key" + # (Actually, widget type is limited to 'choice', 'slider', or 'text' in the above code. + # Therefore, this is not a problem to run this code, but mypy raises error.) study._storage.set_trial_user_attr( - trial._trial_id, key=widget["user_attr_key"], value=value - ) # type: ignore + trial._trial_id, key=widget["user_attr_key"], value=value # type: ignore + ) - st.success("Feedback submitted!") + st.success("Submitted!")