Skip to content

Commit

Permalink
docs: Add ConditionLike doc, standardize w/ SchemaLike
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Sep 16, 2024
1 parent 3e51d1e commit d20109e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
28 changes: 22 additions & 6 deletions altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,17 +835,18 @@ class SchemaLike(Generic[_JSON_VT_co], Protocol): # type: ignore[misc]
"""
Represents ``altair`` classes which *may* not derive ``SchemaBase``.
Should be kept tightly defined to the **minimum** requirements for:
- Converting into a form that can be validated by `jsonschema`_.
- Avoiding calling ``.to_dict()`` on a class external to ``altair``.
Attributes
----------
_schema
A single item JSON Schema using the `type`_ keyword.
.. note::
more accurately described as a ``ClassVar``, see `discussion`_ for blocking issue.
Notes
-----
Should be kept tightly defined to the **minimum** requirements for:
- Converting into a form that can be validated by `jsonschema`_.
- Avoiding calling ``.to_dict()`` on a class external to ``altair``.
- ``_schema`` is more accurately described as a ``ClassVar``
- See `discussion`_ for blocking issue.
.. _jsonschema:
https://github.com/python-jsonschema/jsonschema
Expand All @@ -862,6 +863,21 @@ def to_dict(self, *args, **kwds) -> Any: ...

@runtime_checkable
class ConditionLike(SchemaLike[Literal["object"]], Protocol):
"""
Represents the wrapped state of a conditional encoding or property.
Attributes
----------
condition
One or more (predicate, statement) pairs which each form a condition.
Notes
-----
- Can be extended with additional conditions.
- *Does not* define a default value, but can be finalized with one.
"""

condition: Any
_schema: _TypeMap[Literal["object"]] = {"type": "object"}


Expand Down
28 changes: 22 additions & 6 deletions tools/schemapi/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,17 +833,18 @@ class SchemaLike(Generic[_JSON_VT_co], Protocol): # type: ignore[misc]
"""
Represents ``altair`` classes which *may* not derive ``SchemaBase``.
Should be kept tightly defined to the **minimum** requirements for:
- Converting into a form that can be validated by `jsonschema`_.
- Avoiding calling ``.to_dict()`` on a class external to ``altair``.
Attributes
----------
_schema
A single item JSON Schema using the `type`_ keyword.
.. note::
more accurately described as a ``ClassVar``, see `discussion`_ for blocking issue.
Notes
-----
Should be kept tightly defined to the **minimum** requirements for:
- Converting into a form that can be validated by `jsonschema`_.
- Avoiding calling ``.to_dict()`` on a class external to ``altair``.
- ``_schema`` is more accurately described as a ``ClassVar``
- See `discussion`_ for blocking issue.
.. _jsonschema:
https://github.com/python-jsonschema/jsonschema
Expand All @@ -860,6 +861,21 @@ def to_dict(self, *args, **kwds) -> Any: ...

@runtime_checkable
class ConditionLike(SchemaLike[Literal["object"]], Protocol):
"""
Represents the wrapped state of a conditional encoding or property.
Attributes
----------
condition
One or more (predicate, statement) pairs which each form a condition.
Notes
-----
- Can be extended with additional conditions.
- *Does not* define a default value, but can be finalized with one.
"""

condition: Any
_schema: _TypeMap[Literal["object"]] = {"type": "object"}


Expand Down

0 comments on commit d20109e

Please sign in to comment.