Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-tteixeira
Copy link
Contributor

Describe your changes

Altair charts can have different types depending on what you did to them, but our type annotations don't currently account for that. This PR addresses that.

If you have c1 and c2 like this...

c1 = alt.Chart(...)
c2 = alt.Chart(...)

...then those have type AltairChart, but c1 + c2 is a LayerChart, c1 | c2 is a HConcatChart, etc.

So this PR makes st.altair_chart accept all possible Altair chart types. This is a typing-only change -- it doesn't impact behavior. In fact, what this does is make our type annotations match what our current behavior.

The only thing anyone will notice is that people's editors will stop complaining when you pass these types of charts into st.altair_chart.

GitHub Issue Link (if applicable)

n/a

Testing Plan

  • Explanation of why no additional tests are needed: no behavioral change. And typing is already checked by the mypy tests.
  • Unit Tests (JS and/or Python)
  • E2E Tests
  • Any manual testing needed? No

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 We have recently started adding specific type testing in https://github.com/streamlit/streamlit/tree/develop/lib/tests/streamlit/typing. But it might be that with our current mypy config, we are not even checking altair types at all in our codebase :( its a long-standing tech debt project to do some refactoring around our mypy config related to third-party libraries

@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:other PR contains other type of change impact:users PR changes affect end users labels Jan 18, 2025
@sfc-gh-tteixeira sfc-gh-tteixeira merged commit ae9b46b into develop Jan 21, 2025
33 checks passed
@sfc-gh-tteixeira sfc-gh-tteixeira deleted the altair-typing branch January 21, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:other PR contains other type of change impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants