Created
April 2, 2025 22:09
-
-
Save hansthen/aae79fd705bdfe1d8cd734e3e05f835c to your computer and use it in GitHub Desktop.
casting in streamlit argparse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the supplied values and cast them | |
# to the correct type | |
value = getattr(result, action.dest) | |
match value: | |
case None: | |
pass | |
case [*_]: | |
value = [str(v) for v in value] | |
value = parser._get_values( | |
action, value | |
) | |
case _: | |
value = [str(value)] | |
value = parser._get_values( | |
action, value | |
) | |
# Use it to initialize the widget | |
st.session_state[action.dest] = st.session_state.get( | |
action.dest, | |
value | |
) | |
if action.dest in self.widget_map: | |
value = self.widget_map[action.dest](self, action, value) | |
new_result[action.dest] = value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment