1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
- case: test_mypy_pipe_lambda_noarg_return_type
main: |
from xarray import DataArray
da = DataArray().pipe(lambda data: data)
reveal_type(da) # N: Revealed type is "xarray.core.dataarray.DataArray"
- case: test_mypy_pipe_lambda_posarg_return_type
main: |
from xarray import DataArray
da = DataArray().pipe(lambda data, arg: arg, "foo")
reveal_type(da) # N: Revealed type is "builtins.str"
- case: test_mypy_pipe_lambda_chaining_return_type
main: |
from xarray import DataArray
answer = DataArray().pipe(lambda data, arg: arg, "foo").count("o")
reveal_type(answer) # N: Revealed type is "builtins.int"
- case: test_mypy_pipe_lambda_missing_arg
main: |
from xarray import DataArray
# Call to pipe missing argument for lambda parameter `arg`
da = DataArray().pipe(lambda data, arg: data)
out: |
main:4: error: No overload variant of "pipe" of "DataWithCoords" matches argument type "Callable[[Any, Any], Any]" [call-overload]
main:4: note: Possible overload variants:
main:4: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:4: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_lambda_extra_arg
main: |
from xarray import DataArray
# Call to pipe with extra argument for lambda
da = DataArray().pipe(lambda data: data, "oops!")
out: |
main:4: error: No overload variant of "pipe" of "DataWithCoords" matches argument types "Callable[[Any], Any]", "str" [call-overload]
main:4: note: Possible overload variants:
main:4: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:4: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_function_missing_posarg
main: |
from xarray import DataArray
def f(da: DataArray, arg: int) -> DataArray:
return da
# Call to pipe missing argument for function parameter `arg`
da = DataArray().pipe(f)
out: |
main:7: error: No overload variant of "pipe" of "DataWithCoords" matches argument type "Callable[[DataArray, int], DataArray]" [call-overload]
main:7: note: Possible overload variants:
main:7: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:7: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_function_extra_posarg
main: |
from xarray import DataArray
def f(da: DataArray, arg: int) -> DataArray:
return da
# Call to pipe missing keyword for kwonly parameter `kwonly`
da = DataArray().pipe(f, 42, "oops!")
out: |
main:7: error: No overload variant of "pipe" of "DataWithCoords" matches argument types "Callable[[DataArray, int], DataArray]", "int", "str" [call-overload]
main:7: note: Possible overload variants:
main:7: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:7: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_function_missing_kwarg
main: |
from xarray import DataArray
def f(da: DataArray, arg: int, *, kwonly: int) -> DataArray:
return da
# Call to pipe missing argument for kwonly parameter `kwonly`
da = DataArray().pipe(f, 42)
out: |
main:7: error: No overload variant of "pipe" of "DataWithCoords" matches argument types "Callable[[DataArray, int, NamedArg(int, 'kwonly')], DataArray]", "int" [call-overload]
main:7: note: Possible overload variants:
main:7: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:7: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_function_missing_keyword
main: |
from xarray import DataArray
def f(da: DataArray, arg: int, *, kwonly: int) -> DataArray:
return da
# Call to pipe missing keyword for kwonly parameter `kwonly`
da = DataArray().pipe(f, 42, 99)
out: |
main:7: error: No overload variant of "pipe" of "DataWithCoords" matches argument types "Callable[[DataArray, int, NamedArg(int, 'kwonly')], DataArray]", "int", "int" [call-overload]
main:7: note: Possible overload variants:
main:7: note: def [P`2, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:7: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_function_unexpected_keyword
main: |
from xarray import DataArray
def f(da: DataArray, arg: int, *, kwonly: int) -> DataArray:
return da
# Call to pipe using wrong keyword: `kw` instead of `kwonly`
da = DataArray().pipe(f, 42, kw=99)
out: |
main:7: error: Unexpected keyword argument "kw" for "pipe" of "DataWithCoords" [call-arg]
- case: test_mypy_pipe_tuple_return_type_dataarray
main: |
from xarray import DataArray
def f(arg: int, da: DataArray) -> DataArray:
return da
da = DataArray().pipe((f, "da"), 42)
reveal_type(da) # N: Revealed type is "xarray.core.dataarray.DataArray"
- case: test_mypy_pipe_tuple_return_type_other
main: |
from xarray import DataArray
def f(arg: int, da: DataArray) -> int:
return arg
answer = DataArray().pipe((f, "da"), 42)
reveal_type(answer) # N: Revealed type is "builtins.int"
- case: test_mypy_pipe_tuple_missing_arg
main: |
from xarray import DataArray
def f(arg: int, da: DataArray) -> DataArray:
return da
# Since we cannot provide a precise type annotation when passing a tuple to
# pipe, there's not enough information for type analysis to indicate that
# we are missing an argument for parameter `arg`, so we get no error here.
da = DataArray().pipe((f, "da"))
reveal_type(da) # N: Revealed type is "xarray.core.dataarray.DataArray"
# Rather than passing a tuple, passing a lambda that calls `f` with args in
# the correct order allows for proper type analysis, indicating (perhaps
# somewhat cryptically) that we failed to pass an argument for `arg`.
da = DataArray().pipe(lambda data, arg: f(arg, data))
out: |
main:17: error: No overload variant of "pipe" of "DataWithCoords" matches argument type "Callable[[Any, Any], DataArray]" [call-overload]
main:17: note: Possible overload variants:
main:17: note: def [P`9, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:17: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
- case: test_mypy_pipe_tuple_extra_arg
main: |
from xarray import DataArray
def f(arg: int, da: DataArray) -> DataArray:
return da
# Since we cannot provide a precise type annotation when passing a tuple to
# pipe, there's not enough information for type analysis to indicate that
# we are providing too many args for `f`, so we get no error here.
da = DataArray().pipe((f, "da"), 42, "foo")
reveal_type(da) # N: Revealed type is "xarray.core.dataarray.DataArray"
# Rather than passing a tuple, passing a lambda that calls `f` with args in
# the correct order allows for proper type analysis, indicating (perhaps
# somewhat cryptically) that we passed too many arguments.
da = DataArray().pipe(lambda data, arg: f(arg, data), 42, "foo")
out: |
main:17: error: No overload variant of "pipe" of "DataWithCoords" matches argument types "Callable[[Any, Any], DataArray]", "int", "str" [call-overload]
main:17: note: Possible overload variants:
main:17: note: def [P`9, T] pipe(self, func: Callable[[DataArray, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
main:17: note: def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
|