Skip to content

Type hints allows None for too many parameters #1593

Closed

Description

@Sevans711

Version

2026.6.0

How did you install UXarray?

Source

What happened?

uxarray type hints allow None for too many parameters. For example, in uxarray/core/api.py:

def open_grid(
    grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
    chunks=None,
    use_dual: bool | None = False,
    **kwargs: dict[str, Any],
):
    """Constructs and returns a ``Grid`` from a grid file.
    ...
    use_dual : bool, optional
        Specify whether to use the primal (use_dual=False) or dual (use_dual=True) mesh if the file type is MPAS
    ...
    """
    ...

The docstring and code both expect a bool, not None; there is no special meaning of use_dual=None. So, None should not be allowed in the type hinting here.

Related: #1590

What did you expect to happen?

I expected type hinting for each kwarg to either precisely represent all accepted types, or to be excluded entirely.

Can you provide a MCVE to repoduce the bug?

N/A

Activity

  1. added
    bug
    on Jul 20, 2026
  2. Sevans711 commented on Jul 27, 2026

    @Sevans711
    CollaboratorAuthor

    Briefly clarifying a few points here for future reference:

    • This applies in other cases too, not just use_dual. For example, grid.use_geodataframe() type hints allow engine=None, but the method starts by crashing with ValueError if engine not in ["spatialpandas", "geopandas"]. Other examples include destination in UxDataArray.difference(); start_index in Grid.from_topology(); and tol in Grid.from_structured().
    • I'm not sure how to add regression tests for this sort of thing. Maybe no regression tests are needed? Or, maybe this would be a good opportunity to introduce mypy or pyright checks into the CI pipeline somewhere? See PR Fix use_dual type hints #1612 for more discussion on this question.
  3. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Jul 29, 2026
  4. erogluorhan commented on Jul 29, 2026

    @erogluorhan
    Member

    Briefly clarifying a few points here for future reference:

    • This applies in other cases too, not just use_dual. For example, grid.use_geodataframe() type hints allow engine=None, but the method starts by crashing with ValueError if engine not in ["spatialpandas", "geopandas"]. Other examples include destination in UxDataArray.difference(); start_index in Grid.from_topology(); and tol in Grid.from_structured().
    • I'm not sure how to add regression tests for this sort of thing. Maybe no regression tests are needed? Or, maybe this would be a good opportunity to introduce mypy or pyright checks into the CI pipeline somewhere? See PR Fix use_dual type hints #1612 for more discussion on this question.

    Answering this, and also related to #1612 (comment)

    • I think taking care of all of them in a PR would be great, and @dylannelson could work on that.
    • Regression tests for type hinting might not be needed since even in the codecov reports they are not shown
  5. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Oct 28, 2026
  6. moved this from 📝 To-Do to 🏗 In progress in UXarray Developmenton Oct 28, 2026
  7. moved this from 🏗 In progress to ✅ Done in UXarray Developmenton Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Fields

Priority

Low

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions