Skip to content

TYP: Fix type annotations for np.ma.nomask and np.ma.MaskType #28831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions numpy/ma/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ _ScalarT_co = TypeVar("_ScalarT_co", bound=generic)
# A subset of `MaskedArray` that can be parametrized w.r.t. `np.generic`
_MaskedArray: TypeAlias = MaskedArray[_Shape, dtype[_ScalarT]]

MaskType = bool
nomask: bool
MaskType = bool_
nomask: bool_[Literal[False]]

class MaskedArrayFutureWarning(FutureWarning): ...
class MAError(Exception): ...
Expand Down
6 changes: 5 additions & 1 deletion numpy/typing/tests/data/reveal/ma.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from typing import Any, TypeAlias, TypeVar, assert_type
from typing import Any, Literal, TypeAlias, TypeVar, assert_type

import numpy as np
from numpy import dtype, generic
Expand Down Expand Up @@ -280,3 +280,7 @@ assert_type(np.ma.allequal(AR_f4, MAR_f4, fill_value=False), bool)
assert_type(np.ma.allclose(AR_f4, MAR_f4), bool)
assert_type(np.ma.allclose(AR_f4, MAR_f4, masked_equal=False), bool)
assert_type(np.ma.allclose(AR_f4, MAR_f4, rtol=.4, atol=.3), bool)

assert_type(np.ma.nomask, np.bool[Literal[False]])
# https://github.com/python/mypy/issues/18974
assert_type(np.ma.MaskType, type[np.bool]) # type: ignore[assert-type]
Loading