-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move check_* utils to own file #8764
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that the methods are not yet removed from utils.py
or am I missing something. Also, it seems to not yet cover all relevant elements (e.g data editor is missing?)
lib/streamlit/elements/policies.py
Outdated
|
||
from typing import TYPE_CHECKING, Any | ||
|
||
import streamlit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit annoyed by all the import cycle warnings. I believe this import might be the issue. Can we move this import down into the function from where it is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the circular imports at some places in the code base are pretty annoying. I have spent some time today looking into refactoring it and refactoring everything including the delta generator are on top of my list 😄 moving the imports down - if it works at all as it opened a rabbit hole earlier - just hides the original problem that the code is not pretty well abstracted. I guess eventually we have to start cleaning it up top down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving the imports down - if it works at all as it opened a rabbit hole earlier - just hides the original problem that the code is not pretty well abstracted
Yeah, I think the better solution would be to have some internal import for exception and warning, but I'm not sure if that is viable without bigger refactoring. But just having a blank streamlit
import here on top doesn't feel super good. Overall, it's better to move this import down and all the other check_
imports to the top level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its a delta generator function, the best way would likely be to have to pass the deltagenerator to the function instead of importing a global object. But this surfaces other import issues at other places; so I think the first step has to be abstracting the delta generator and probably move out the main_dg
and other *_dg
variables and dg_stack
out and work with a singleton factory or so. But that requires a little bit more time
73b59b9
to
b5aad90
Compare
94e6571
to
12ec5c3
Compare
@LukasMasuch could you please have another look? The CodeScan things look like a lot, but I have moved the imports within the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I think it would be good to move policies
and/or utils
into the element/lib
folder. These are the only two non-element modules within this folders, and it feels like element/lib
would be a better place.
12ec5c3
to
18888e0
Compare
Great point, I have moved both utils files |
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
streamlit.elements.lib.policies
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
streamlit.elements.lib.policies
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
streamlit.elements.lib.policies
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
streamlit.elements.lib.policies
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
streamlit.elements.lib.policies
from streamlit.elements.lib.policies import ( | ||
check_cache_replay_rules, | ||
check_callback_rules, | ||
check_session_state_rules, | ||
) |
Check notice
Code scanning / CodeQL
Cyclic import Note
Describe your changes
In streamlit/elements/utils.py we have some
check_*
functions that are used to enforce certain rules. This PR moves them to their ownpolicies.py
file for cleaner abstraction.Also, tests for
check_cache_replay_rules
were missing that are added now.This is in preparation of adding a new
check_*
policy function in this PR: https://github.com/streamlit/streamlit/pull/8756/filesGitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.