Current solution however has some limitations/drawbacks:
We need to maintain code on our side, which we might be able to out source to pydantic.
We don't support nested structures (or very limited). E.g. config can't check that a List[str] is actually a list of strings (today it only supports list - and checking that it is a list....).
Overloaded init functions are not supported (both wrt. input type conversion, and yaml/json schema. Supporting this could significantly improve e.g. yaml schema user experience for complex plugins in webviz-subsurface (if you give one argument, the editor could immediately fill in other required arguments matching that function signature).
...along the same route is supporting TypedDict as argument type hint (early check that keys are correct/present). Complex plugins sometimes typically have arguments which are dictionaries. Giving them the possibility to use TypedDict would improve the user experience.
As stated in @typing.overload documentation, only the last function signature is by default available during runtime. This gives some challenges, as we probably don't want to introduce some specific @overload Webviz decorator (such that plugin authors can use mypy natively, as well as not introduce a new concept/feature to learn). However, the Python docs can be interpreted as it is not by default available during runtime⭑
⭑ Since webviz docs and webviz schema are user entrypoints, we are in control of import order of different packages. The following could be used in those subcommands to monkeypatch overload to do what we want. Prototype code:
webviz-config
today supports the following:__init__
). Also reports early if input argument is of type wrong (non-castable). https://github.com/equinor/webviz-config/blob/76aeb0102d7a7395a9af83f3935b28561c508564/webviz_config/_config_parser.py#L88-L107json/yaml schema
based on type hinted plugin__init__
function. See this video for an example of todays functionality. https://github.com/equinor/webviz-config/blob/76aeb0102d7a7395a9af83f3935b28561c508564/webviz_config/_docs/_create_schema.py#L56-L71Current solution however has some limitations/drawbacks:
pydantic
.List[str]
is actually a list of strings (today it only supportslist
- and checking that it is a list....).yaml/json
schema. Supporting this could significantly improve e.g. yaml schema user experience for complex plugins inwebviz-subsurface
(if you give one argument, the editor could immediately fill in other required arguments matching that function signature).TypedDict
as argument type hint (early check that keys are correct/present). Complex plugins sometimes typically have arguments which are dictionaries. Giving them the possibility to useTypedDict
would improve the user experience.Related issues:
199
358
Additional information:
pydantic
available here: https://github.com/samuelcolvin/pydantic/issues/2127#issuecomment-728285603.@typing.overload
documentation, only the last function signature is by default available during runtime. This gives some challenges, as we probably don't want to introduce some specific@overload
Webviz decorator (such that plugin authors can usemypy
natively, as well as not introduce a new concept/feature to learn). However, the Python docs can be interpreted as it is not by default available during runtime⭑⭑ Since
webviz docs
andwebviz schema
are user entrypoints, we are in control of import order of different packages. The following could be used in those subcommands to monkeypatchoverload
to do what we want. Prototype code:will give as output