Skip to content

Commit

Permalink
refactor(typing): reduce type ignores in api.py (#3480)
Browse files Browse the repository at this point in the history
* refactor(typing): reduce type ignores in `api.py`

* feat(typing): adds `_is_undefined` guard

Direct copy from another PR, but is helpful here https://github.com/dangotbanned/altair/blob/d607c70824860ef3478d7d3996d26dc516d69369/altair/vegalite/v5/api.py#L504

* fix(typing): `ignore[index]` from #3455

* fix(typing): `[ignore[arg-type]` from #3452

* refactor(typing): use `_is_undefined` in some cases

* refactor: reduce code duplication in `Chart.to_dict`

* fix(typing): Recover `TopLevelMixin.resolve_` return types

I removed these in 6adf564 due to how complex they were getting, but both `mypy` and `pyright` seem happy with this solution

* fix(typing): narrow annotated types for `_check_if_valid_subspec`

Following investigation during #3480 (comment)

* refactor: remove unused `_wrapper_classes` argument from `SchemaBase`

Fixes:
- #3480 (comment)
- #3480 (comment)
- #3480 (comment)
  • Loading branch information
dangotbanned authored Jul 20, 2024
1 parent 7f514c9 commit 72bd84d
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 162 deletions.
13 changes: 2 additions & 11 deletions altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,10 +1087,7 @@ def _default_wrapper_classes(cls) -> Iterator[type[SchemaBase]]:

@classmethod
def from_dict(
cls: type[TSchemaBase],
dct: dict[str, Any],
validate: bool = True,
_wrapper_classes: Iterable[type[SchemaBase]] | None = None,
cls: type[TSchemaBase], dct: dict[str, Any], validate: bool = True
) -> TSchemaBase:
"""Construct class from a dictionary representation
Expand All @@ -1100,10 +1097,6 @@ def from_dict(
The dict from which to construct the class
validate : boolean
If True (default), then validate the input against the schema.
_wrapper_classes : iterable (optional)
The set of SchemaBase classes to use when constructing wrappers
of the dict inputs. If not specified, the result of
cls._default_wrapper_classes will be used.
Returns
-------
Expand All @@ -1117,9 +1110,7 @@ def from_dict(
"""
if validate:
cls.validate(dct)
if _wrapper_classes is None:
_wrapper_classes = cls._default_wrapper_classes()
converter = _FromDict(_wrapper_classes)
converter = _FromDict(cls._default_wrapper_classes())
return converter.from_dict(dct, cls)

@classmethod
Expand Down
Loading

0 comments on commit 72bd84d

Please sign in to comment.