Skip to content

An attempt to make MyPy completely happy

Alec Thomson requested to merge mypy_fixes into main

Main fix was to move from ArrayLike to typed NDArrays. I think I've captured all the correct types with that.

It was not possible to get index_tools completely error-free. Since some of the args / variables are overwritten MyPy gets very grumpy. We may want to consider some refactoring there in the future since that will help readabilitiy. I've left the mypy log below for reference.

I've also left a couple of little TODOs where I wasn't exactly sure what should go in certain places.

MyPy log:

❯ mypy spinifex
spinifex/ionospheric/index_tools.py:61: error: Invalid index type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]" for "ndarray[Any, dtype[floating[_64Bit]]]"; expected type "Union[SupportsIndex, tuple[SupportsIndex, ...]]"  [index]
spinifex/ionospheric/index_tools.py:63: error: Unsupported operand types for - ("generic" and "int")  [operator]
spinifex/ionospheric/index_tools.py:63: error: Unsupported operand types for - ("str" and "int")  [operator]
spinifex/ionospheric/index_tools.py:63: error: Unsupported operand types for - ("bytes" and "int")  [operator]
spinifex/ionospheric/index_tools.py:63: error: Unsupported operand types for - ("memoryview[int]" and "int")  [operator]
spinifex/ionospheric/index_tools.py:63: note: Left operand is of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"
spinifex/ionospheric/index_tools.py:64: error: Unsupported operand types for > ("int" and "complex")  [operator]
spinifex/ionospheric/index_tools.py:64: note: Left operand is of type "Union[int, float, complex]"
spinifex/ionospheric/index_tools.py:67: error: Unsupported operand types for + ("generic" and "int")  [operator]
spinifex/ionospheric/index_tools.py:67: error: Unsupported operand types for + ("memoryview[int]" and "int")  [operator]
spinifex/ionospheric/index_tools.py:67: note: Left operand is of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"
spinifex/ionospheric/index_tools.py:67: error: Unsupported operand types for + ("str" and "int")  [operator]
spinifex/ionospheric/index_tools.py:67: error: Unsupported operand types for + ("bytes" and "int")  [operator]
spinifex/ionospheric/index_tools.py:68: error: Unsupported operand types for <= ("int" and "complex")  [operator]
spinifex/ionospheric/index_tools.py:68: note: Left operand is of type "Union[Any, int, float, complex]"
spinifex/ionospheric/index_tools.py:74: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]")  [assignment]
spinifex/ionospheric/index_tools.py:76: error: Unsupported target for indexed assignment ("Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]")  [index]
spinifex/ionospheric/index_tools.py:76: error: Invalid index type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]" for "ndarray[Any, dtype[floating[_64Bit]]]"; expected type "Union[SupportsIndex, tuple[SupportsIndex, ...]]"  [index]
spinifex/ionospheric/index_tools.py:76: error: Value of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]" is not indexable  [index]
spinifex/ionospheric/index_tools.py:76: error: Unsupported operand types for + (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:76: note: Left operand is of type "Union[Any, str, int]"
spinifex/ionospheric/index_tools.py:79: error: Unsupported target for indexed assignment ("Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]")  [index]
spinifex/ionospheric/index_tools.py:79: error: Unsupported operand types for <= (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:79: note: Left operand is of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"
spinifex/ionospheric/index_tools.py:79: error: Unsupported operand types for >= (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:82: error: Value of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]" is not indexable  [index]
spinifex/ionospheric/index_tools.py:82: error: Unsupported target for indexed assignment ("Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]")  [index]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for - (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:82: note: Left operand is of type "Union[Any, str, int]"
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for <= ("int" and "generic")  [operator]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for <= ("int" and "complex")  [operator]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for <= ("int" and "memoryview[int]")  [operator]
spinifex/ionospheric/index_tools.py:82: note: Left operand is of type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for <= (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for >= ("str" and "int")  [operator]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for >= ("bytes" and "int")  [operator]
spinifex/ionospheric/index_tools.py:82: error: Unsupported operand types for >= (likely involving Union)  [operator]
spinifex/ionospheric/index_tools.py:83: error: Argument 1 to "_get_weights" has incompatible type "ndarray[Any, dtype[floating[_64Bit]]]"; expected "float"  [arg-type]
spinifex/ionospheric/index_tools.py:83: error: Argument 3 to "_get_weights" has incompatible type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
spinifex/ionospheric/index_tools.py:84: error: Argument "idx2" to "Indices" has incompatible type "Union[generic, bool, int, float, complex, str, bytes, memoryview[int]]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
spinifex/ionospheric/index_tools.py:155: error: Argument 2 to "_get_weights" has incompatible type "signedinteger[Any]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
spinifex/ionospheric/index_tools.py:155: error: Argument 3 to "_get_weights" has incompatible type "signedinteger[Any]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
spinifex/ionospheric/index_tools.py:156: error: Argument "idx1" to "Indices" has incompatible type "signedinteger[Any]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
spinifex/ionospheric/index_tools.py:156: error: Argument "idx2" to "Indices" has incompatible type "signedinteger[Any]"; expected "ndarray[Any, dtype[signedinteger[_64Bit]]]"  [arg-type]
Found 36 errors in 1 file (checked 25 source files)

Merge request reports

Loading