Skip to content

Improve type signatures of pipe methods to enable type checkers to flag erroneous usages #9997

Closed
@chuckwondo

Description

@chuckwondo

What is your issue?

The type annotations of xarray.Dataset.pipe, xarray.DataArray.pipe, and xarray.DataTree.pipe should be enhanced to address the following shortcomings in terms of what type checkers cannot flag due to the imprecise typing currently in place:

  1. Incorrect number of arguments
  2. Incorrect argument types
  3. Code suggestions for chaining after the pipe (only an issue for Datatree.pipe)

Note that in the case of specifying a tuple (function + keyword) as the first argument to pipe, only item 3 can be addressed because there's no way to fully specify the function's type signature when the function does not take the dataset/array/tree as its first argument.

In this case, this can be addressed by using a lambda instead. In essence, my recommendation would be for users of pipe not to use the tuple form so that more robust type checking can be performed.

NOTE: I plan to submit a PR for this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions