Skip to content

Conversation

@tconkling
Copy link
Contributor

@tconkling tconkling commented Dec 17, 2020

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.dg property 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:

  • We get autocompletion for DG properties and methods from within the mixins
  • We can stop disabling mypy via # type: ignore within mixins

@tconkling tconkling requested a review from a team December 17, 2020 15:22
Comment on lines -134 to -136
import numpy as np
import pandas as pd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports were unused

Copy link
Contributor

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...

Copy link
Contributor Author

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.

Comment on lines -134 to -138
# 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)
Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Contributor

@akrolsmir akrolsmir left a 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!

Comment on lines -134 to -136
import numpy as np
import pandas as pd

Copy link
Contributor

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...

Comment on lines -134 to -138
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@akrolsmir akrolsmir merged commit 20baedb into streamlit:develop Dec 17, 2020
@tconkling tconkling deleted the tim/DGMixinTypes branch December 17, 2020 17:32
tconkling added a commit to tconkling/streamlit that referenced this pull request Dec 21, 2020
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants