Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typing): Fully annotate
api.py
(#3508)
* ci(ruff): Add `ANN` rules for `api.py` only To highlight all the missing annotations to fix and autofix `None` return * feat(typing): Complete annotations for most `api` functions Excluding `*args` on `ChartType` wrappers. They need to be defined in alignment in multiple places, which is more complex * feat(typing): Annotate more expr/params in `api` * feat(typing): Various changes to enforce `dict[str, Any]` instead of `dict` Among these, many locations already assume `str` keys in the implementation - without checking * feat(typing): Misc minor method annotations * feat(typing): Use `ChartType` in all `ChartType` dunder methods * fix(ruff): Ignore some `ANN` rules that won't be fixed * chore: add pyright ignore from #3492 * feat(typing): Improve `ChartType` constructor/factory annotations * feat(typing): Annotate remaining functions in `api` * feat(typing): Complete `RepeatChart` annotations * fix(typing): Resolve Liskov violations ``` 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 ``` * chore(typing): Update more `dict` -> `dict[str, Any]` * style(ruff): fix whitespace * chore: Remove TODO fixed in #3480 * fix(typing): Enable `ANN003` and fix all in `api` * fix(typing): Enable `ANN002` and fix all in `api` * chore(ruff): Add note on `ANN` This could later be extended to other modules, but for now `api` is complete. * fix(typing): Add missing `FacetChart` annotations To align with the other `ChartType`s
- Loading branch information