-
Notifications
You must be signed in to change notification settings - Fork 795
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
feat(typing): Fully annotate api.py
#3508
Conversation
To highlight all the missing annotations to fix and autofix `None` return
Excluding `*args` on `ChartType` wrappers. They need to be defined in alignment in multiple places, which is more complex
…`dict` Among these, many locations already assume `str` keys in the implementation - without checking
``` altair\vegalite\v5\api.py:4368: error: Argument 1 of "__iadd__" is incompatible with "__add__" of supertype "TopLevelMixin"; supertype defines the argument type as "Chart | RepeatChart | ConcatChart | HConcatChart | VConcatChart | FacetChart | LayerChart" [override] def __iadd__(self, other: LayerChart | Chart) -> Self: ^~~~~~~~~~~~~~~~~~~~~~~~~ altair\vegalite\v5\api.py:4368: note: This violates the Liskov substitution principle altair\vegalite\v5\api.py:4368: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides altair\vegalite\v5\api.py:4376: error: Argument 1 of "__add__" is incompatible with supertype "TopLevelMixin"; supertype defines the argument type as "Chart | RepeatChart | ConcatChart | HConcatChart | VConcatChart | FacetChart | LayerChart" [override] def __add__(self, other: LayerChart | Chart) -> Self: ^~~~~~~~~~~~~~~~~~~~~~~~~ altair\vegalite\v5\api.py:4376: note: This violates the Liskov substitution principle altair\vegalite\v5\api.py:4376: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides ```
This could later be extended to other modules, but for now `api` is complete.
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's very satisfying to see api.py
finally being fully typed :) Didn't have it in me when doing #3143 to go all the way. Thanks!
Either all of these functions should expect SchemaBase | dict or all SchemaBase.
Unless I'm missing something, there does not seem to be a way to use a dict to build a compound chart this way.
Thanks for uncovering it! Agree with your suggestion, dicts don't make sense at this stage.
Thanks! ❤️ |
@binste would it be worth opening an issue for the Minimal Repro section? I'd still need to double-check the implications of this, but it should mean these two could be simplified significantly: altair/altair/vegalite/v5/api.py Lines 3844 to 3874 in a847833
altair/altair/vegalite/v5/api.py Lines 3877 to 3912 in a847833
Since |
This could later be extended to other modules, but for now
api
is complete.Follows work in #3480
Main motivation for this was trying to understand all of the private functions.
There seems to be an assumption that
ChartType
's can be combined withdict
's early on (_check_if_valid_subspec
,_check_if_can_be_layered
), but later code assumes all deriveSchemaBase
.Minimal Repro
Test code block
Test Failures
Summary
Without typing information, finding this the conflict between
_combine_subchart_data
and the earlier_check_if_valid_subspec
,_check_if_can_be_layered
is much less clear.Suggestion
Either all of these functions should expect
SchemaBase | dict
or allSchemaBase
.Unless I'm missing something, there does not seem to be a way to use a
dict
to build a compound chart this way.