xarray-contrib / datatree

WIP implementation of a tree-like hierarchical data structure for xarray.
https://xarray-datatree.readthedocs.io
Apache License 2.0
161 stars 43 forks source link

Typing: `DataTree[Unknown]` #313

Open etienneschalk opened 4 months ago

etienneschalk commented 4 months ago

Try to instantiate a DataTree:

root = DataTree(name="root")

VSCode with Pylance will complain:

Type of "root" is partially unknown
  Type of "root" is "DataTree[Unknown]"
Pylance[reportUnknownVariableType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUnknownVariableType)
(variable) root: DataTree[Unknown]

Going to the DataTree class definition and hovering the Mapping parent class:

Expected type arguments for generic class "Mapping"
Pylance[reportMissingTypeArgument](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingTypeArgument)
(class) Mapping

Same for NamedNode:

Expected type arguments for generic class "NamedNode"
Pylance[reportMissingTypeArgument](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingTypeArgument)
(class) NamedNode
A TreeNode which knows its own name.

Implements path-like relationships to other nodes in its tree.

If we compare to the Dataset definition in xarray:

https://github.com/pydata/xarray/blob/ff0d056ec9e99dece0202d8d73c1cb8c6c20b2a1/xarray/core/dataset.py#L511

We can see that the type parameters of Mapping are provided