Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/core/test_type_hints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ast
from pathlib import Path

ROOT = Path(__file__).parents[2]


def _annotation(source: Path, function_name: str, parameter_name: str) -> str:
tree = ast.parse(source.read_text())
function = next(
node
for node in ast.walk(tree)
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
and node.name == function_name
)
parameter = next(arg for arg in function.args.args if arg.arg == parameter_name)
return ast.unparse(parameter.annotation)


def test_use_dual_type_hints_do_not_allow_none():
api = ROOT / "uxarray" / "core" / "api.py"
grid = ROOT / "uxarray" / "grid" / "grid.py"

assert _annotation(api, "open_grid", "use_dual") == "bool"
assert _annotation(api, "open_dataset", "use_dual") == "bool"
assert _annotation(api, "open_mfdataset", "use_dual") == "bool"
assert _annotation(grid, "from_dataset", "use_dual") == "bool"
6 changes: 3 additions & 3 deletions uxarray/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
def open_grid(
grid_filename_or_obj: str | os.PathLike[Any] | dict | xr.Dataset,
chunks=None,
use_dual: bool | None = False,
use_dual: bool = False,
**kwargs: dict[str, Any],
):
"""Constructs and returns a ``Grid`` from a grid file.
Expand Down Expand Up @@ -348,7 +348,7 @@ def open_dataset(
filename_or_obj: str | os.PathLike[Any] | xr.Dataset | None = None,
chunks=None,
chunk_grid: bool = True,
use_dual: bool | None = False,
use_dual: bool = False,
grid_kwargs: dict[str, Any] | None = None,
**kwargs: dict[str, Any],
) -> UxDataset:
Expand Down Expand Up @@ -475,7 +475,7 @@ def open_mfdataset(
paths: str | os.PathLike,
chunks=None,
chunk_grid: bool = True,
use_dual: bool | None = False,
use_dual: bool = False,
grid_kwargs: dict[str, Any] | None = None,
**kwargs: dict[str, Any],
) -> UxDataset:
Expand Down
2 changes: 1 addition & 1 deletion uxarray/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __init__(
cross_section = UncachedAccessor(GridCrossSectionAccessor)

@classmethod
def from_dataset(cls, dataset, use_dual: bool | None = False, **kwargs):
def from_dataset(cls, dataset, use_dual: bool = False, **kwargs):
"""Constructs a ``Grid`` object from a dataset.
Parameters
Expand Down