Match: SyntaxError: invalid syntax

Summary

File β€œ/app/ai-talks/ai_talks/chat.py”, line 80
match role_kind:
^
SyntaxError: invalid syntax

Pipfile

[[source]]

url = β€œSimple index”
verify_ssl = true
name = β€œpypi”

[packages]
streamlit = β€œ>=1.21.0”
streamlit-chat = β€œ>=0.0.2.2”
streamlit-option-menu = β€œ>=0.3.2”
openai = β€œ>=0.27.4”
gtts = β€œ>=2.3.1”
bokeh = β€œ==2.4.2”
streamlit-bokeh-events = β€œ>=0.1.2”
watchdog = β€œ>=3.0.0”
curl-cffi = β€œ>=0.5.5”

[dev-packages]

[requires]
python_version = β€œ3.11”

requirements

pip>=23.1
streamlit>=1.21.0
streamlit-chat>=0.0.2.2
streamlit_option_menu>=0.3.2
openai>=0.27.4
gtts>=2.3.1
bokeh==2.4.2
streamlit-bokeh-events>=0.1.2
watchdog>=3.0.0
curl_cffi>=0.5.5

Please provide sufficient information.
https://discuss.streamlit.io/t/using-streamlit-how-to-post-a-question-in-the-streamlit-forum/30960
It is probably a syntax error in your python file.

Code like this

match role_kind:
          case st.session_state.locale.radio_text1:
                c2.selectbox(label=st.session_state.locale.select_placeholder2, key="role",
                options=st.session_state.locale.ai_role_options)
           case st.session_state.locale.radio_text2:
                c2.text_input(label=st.session_state.locale.select_placeholder3, key="role")

You need at least Python 3.10 version to use this new syntax with match case statements.

Trying to compile your code in Python 3.11 yields:

File "test.py", line 5
    case st.session_state.locale.radio_text2:
                                             ^
IndentationError: unindent does not match any outer indentation level

as expected since the case clauses are not aligned.

1 Like

yes, i use python 3.11 version native env. But streamlt seems not support this version??
And when I use if/else replace match case, it succeed

Streamlit works fine with Python 3.11, Streamlit Cloud doesn’t. The relevant syntax hasn’t changed from 3.10 to 3.11, the error message is exactly the same with both versions.

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.