-
Notifications
You must be signed in to change notification settings - Fork 4k
Add type annotations to DeltaGenerator mixins #2475
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
Conversation
| import numpy as np | ||
| import pandas as pd | ||
|
|
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.
These imports were unused
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.
Glad to remove them!
Tangential: I've often seen unused or "misordered" imports lying throughout or codebase; wonder if there's a way for our static analysis tool to find these for us. Tracking ticket filed #1808 a long time ago, dunno when we'll get to it though...
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.
PyCharm catches these (and automatically cleans them up, if you ask it to). That (probably) doesn't help us with auto-analysis on CircleCI, but it is fantastically useful while coding.
| # Import dynamically, to resolve circular dependency | ||
| from streamlit.delta_generator import DeltaGenerator | ||
|
|
||
| # Cast self to DeltaGenerator, to resolve mypy type issues | ||
| dg = cast(DeltaGenerator, self) |
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.
Converted to the new self.dg convention used in the other mixins
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.
❤️
akrolsmir
left a comment
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.
This is awesome -- thanks for the refactor, double thanks for doing it on an off-day, TRIPLE THANKS for splitting it up for easier reviewing!
| import numpy as np | ||
| import pandas as pd | ||
|
|
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.
Glad to remove them!
Tangential: I've often seen unused or "misordered" imports lying throughout or codebase; wonder if there's a way for our static analysis tool to find these for us. Tracking ticket filed #1808 a long time ago, dunno when we'll get to it though...
| # Import dynamically, to resolve circular dependency | ||
| from streamlit.delta_generator import DeltaGenerator | ||
|
|
||
| # Cast self to DeltaGenerator, to resolve mypy type issues | ||
| dg = cast(DeltaGenerator, self) |
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.
❤️
* develop: Extract st.container, columns, container out of delta_generator.py (streamlit#2487) Remove the unused variables inside protos (streamlit#2486) Stop running cypress-flaky-approval for each PR (streamlit#2490) Dynamically import git, and fail gracefully if missing (streamlit#2482) Bump React to 17.0.1 (streamlit#2453) Fix emojis (streamlit#2480) Add missing copyright headers (streamlit#2478) Stop requiring watchdog when installing Streamlit on Macs (streamlit#2470) Minor tweak to PyArrow warning message (streamlit#2472) Use a set literal (streamlit#2476) Add type annotations to DeltaGenerator mixins (streamlit#2475) Update change log Up version to 0.73.0 Don't require pyarrow on 3.9, and show a warning on custom components (streamlit#2452)
Our DeltaGenerator mixin classes access DeltaGenerator members, but the type system doesn't know that they're actually "part" of the DeltaGenerator class.
This PR adds a
self.dgproperty to each mixin. It just does a mypy cast from self to DeltaGenerator. (And it avoids importing DeltaGenerator, to prevent circular import hell.)This has two benefits:
# type: ignorewithin mixins