Skip to content

Instantly share code, notes, and snippets.

@hansthen
Created April 2, 2025 22:09
Show Gist options
  • Save hansthen/aae79fd705bdfe1d8cd734e3e05f835c to your computer and use it in GitHub Desktop.
Save hansthen/aae79fd705bdfe1d8cd734e3e05f835c to your computer and use it in GitHub Desktop.
casting in streamlit argparse
# 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