Summary
Suppose I have created some variables in session_state in the utils.py module.
Suppose also that I import the utils module in another main.py file.
What are the best practices for using session_state variables created in the utils module in the main file so that Pydantic on my IDE (Vs Code) automatically highlights methods for the variable type?
I wonder if there is any way to type annoted a session_state variable across files whithout the need to create a tyoe annotated local variable?
From what I have explored so far, I have found that Pydantic identifies a variable accessed in the session_state as a function regardless of the actual variable type.
The only way around this behaviour I have found was to create type annotated local variables, but is this the best practice? I though that the session_state was created also to make this thing not happen.
Examples below.
Steps to reproduce
Code snippet:
# utils.py
def foo():
# whithin this file, Pydantic will now auto-complete and higlight list methods in the lines below
st.session_state.var_a: list = [0, 1, 2]
# when typing the below command the list method append will be highlighted
st.session_state.var_a.append(3)
# main.py
from utils import foo
foo()
# now if I need to access the session_state variable created in the utils module Pydantic will not highlight the list method
st.session_state.var_a.append(4)
# the only way I found to make the Pydantic highlitgh work, is to assign the session_state variable to a type annotated local variable, as below
var_a: list = st.session_state.var_a
# now whithin this file the Pydantic highlighting will work for the local variable
var_a.append(5)
Debug info
- Streamlit version: 1.22
- Python version: 3.11
- PipEnv