L iZUddlmZddlmZmZmZddlmZmZm Z m Z ddl m Z ddl mZmZmZmZddlmZmZddlmZmZer ddlmZdd lmZe j8eZd ed <dd Z d a!ded< d ddZ"GddeZ#ddZ$ddZ% ddddd d dZ&d!dZ'y)") annotations) TYPE_CHECKINGAnyFinal)configerrorsloggerruntime) is_in_form)StreamlitAPIWarning.StreamlitFragmentWidgetsNotAllowedOutsideError!StreamlitInvalidFormCallbackError'StreamlitValueAssignmentNotAllowedError)get_script_run_ctxin_cached_function)WidgetCallbackget_session_state)Sequence)DeltaGeneratorr_LOGGERc^tjrt|r | tyyy)zEnsures that widgets other than `st.form_submit_button` within a form don't have an on_change callback set. Raises ------ StreamlitInvalidFormCallbackError: Raised when the described rule is violated. N)r existsr r)dg on_changes e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/lib/policies.pycheck_callback_rulesr*s-~~JrNy/D/110ENFbool_shown_default_value_warningTc|tjsyt}|j|sy|s t ||2t s+t jdsddlm }|d|ddayyyy) a|Ensures that no values are set for widgets with the given key when writing is not allowed. Additionally, if `global.disableWidgetStateDuplicationWarning` is False a warning is shown when a widget has a default value but its value is also set via session state. Raises ------ StreamlitAPIException: Raised when the described rule is violated. N)keyz+global.disableWidgetStateDuplicationWarningr)warningzThe widget with key "zX" was created with a default value but also had its value set via the Session State API.T) r rris_new_state_valuerrr get_option streamlitr") default_valuer!writes_allowed session_stater"s rcheck_session_state_rulesr);s  {'..*%'M  + +C 0 5#>> !,!!"OP%#C5)A A (,$Q- "rc eZdZdfd ZxZS)CachedWidgetWarningc$t|dy)Na# Your script uses a widget command in a cached function (function decorated with `@st.cache_data` or `@st.cache_resource`). This code will only be called when we detect a cache "miss", which can lead to unexpected results. To fix this, move all widget commands outside the cached function. )super__init__)self __class__s rr.zCachedWidgetWarning.__init__ds   rreturnNone)__name__ __module__ __qualname__r. __classcell__)r0s@rr+r+cs    rr+cZtjrddlm}|t yy)avCheck if a widget is allowed to be used in the current context. More specifically, this checks if the current context is inside a cached function that disallows widget usage. If so, it raises a warning. If there are other similar checks in the future, we could extend this function to check for those as well. And rename it to check_widget_usage_rules. r exceptionN)rgetr%r:r+r9s rcheck_cache_replay_rulesr<qs&' %'(  rc$t}| |jy|j}|jj}|y|j }t |t |kr tt|D]\}}|||k7sty)a[Ensures that the current widget is not written outside of the fragment's delta path. Should be called by ever element that acts as a widget. We don't allow writing widgets from within a widget to the outside path because it can lead to unexpected behavior. For elements, this is okay because they do not trigger a re-run. N) rcurrent_fragment_idcurrent_fragment_delta_path _active_dg_cursor delta_pathlenr enumerate)rctxr?current_cursorcurrent_cursor_delta_pathindex path_indexs rcheck_fragment_path_policyrJs  C {c--5"%"A"A]]**N . 9 9 $%,G(HH<>>''BCCz $U +z 9@B BCrN)r&r'enable_check_callback_rulescft|t|r t||t|||y)z7Check all widget policies for the given DeltaGenerator.)r&r!r'N)rJr<rr))rr!rr&r'rKs rcheck_widget_policiesrMs.r""R+#^rcp|stjdd|dvrtjd|dy)Nz`label` got an empty value. This is discouraged for accessibility reasons and may be disallowed in the future by raising an exception. Please provide a non-empty label and hide it with label_visibility if needed.T) stack_info)visiblehidden collapsedz%Unsupported label_visibility option 'z7'. Valid values are 'visible', 'hidden' or 'collapsed'.)rr"rStreamlitAPIException)labellabel_visibilitys rmaybe_raise_label_warningsrVsZ    AA**34D3EFC D  Br)rrrWidgetCallback | Noner2r3)T)r&rr! str | Noner'rr2r3r1)rrr2r3)N)rrr!rXrrWr&zSequence[Any] | Any | Noner'rrKrr2r3)rTrXrUrXr2r3)( __future__rtypingrrrr%rrr r !streamlit.elements.lib.form_utilsr streamlit.errorsr r rr7streamlit.runtime.scriptrunner_utils.script_run_contextrrstreamlit.runtime.staterrcollections.abcrstreamlit.delta_generatorr get_loggerr4r__annotations__rrr)r+r<rJrMrVrrrds #,,558 F(8#""8,, 2&+d*AE%,%,'%,9=%, %,P  -   ) CJ(, 15(, % .   "& &  r