Skip to content

Conversation

@MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Apr 26, 2025

I've tried specialising this further with:

@overload
def getmask(a: np.ndarray[_ShapeT_co, _DTypeT_co]) -> np.ndarray[_ShapeT_co, dtype[bool_]] | bool_: ...
@overload
def getmask(a: ArrayLike) -> bool_: ...

but then the tests fail with

E   AssertionError: Reveal mismatch at line 286
    
    error:
    Expression is of type "Any", not
    "ndarray[tuple[int, ...], dtype[numpy.bool[builtins.bool]]] | numpy.bool[builtins.bool]"
     [assert-type]
        assert_type(np.ma.getmask(MAR_1d), NDArray[np.bool] | np.bool)

for

assert_type(np.ma.getmask(MAR_1d), NDArray[np.bool] | np.bool)

@jorenham jorenham self-requested a review April 26, 2025 14:26
@MarcoGorelli MarcoGorelli marked this pull request as ready for review April 26, 2025 14:56
@jorenham jorenham added the component: numpy.ma masked arrays label Apr 26, 2025
@jorenham
Copy link
Member

I've tried specialising this further with:

@overload
def getmask(a: np.ndarray[_ShapeT_co, _DTypeT_co]) -> np.ndarray[_ShapeT_co, dtype[bool_]] | bool_: ...
@overload
def getmask(a: ArrayLike) -> bool_: ...

The _DTypeT_co seems redundant; maybe removing it helps?
These overloads are also overlapping in an incompatible way now, because ArrayLike is broader than np.ndarray, but the bool_ it returns is narrower than the return type of the other overload.

@MarcoGorelli
Copy link
Member Author

ah right, thanks! now it passes (except one which PyRight detects accurates but MyPy doesn't, similar to in another issue)

@jorenham
Copy link
Member

except one which PyRight detects accurates but MyPy doesn't

yea... mypy can be a bit "special" in some situations 😅

@jorenham
Copy link
Member

needs a rebase

@jorenham jorenham merged commit 1923b38 into numpy:main Apr 26, 2025
75 checks passed
@jorenham
Copy link
Member

Thanks Marco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants