Skip to content

Commit 1d7939e

Browse files
authored
Merge pull request numpy#19436 from BvB93/flagsobj2
ENH: Improve the annotations of `flagsobj`
2 parents 882f00b + 996e095 commit 1d7939e

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

numpy/core/multiarray.pyi

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ from numpy.typing import (
7979
)
8080

8181
if sys.version_info >= (3, 8):
82-
from typing import SupportsIndex, Final, Literal as L
82+
from typing import SupportsIndex, final, Final, Literal as L
8383
else:
84-
from typing_extensions import SupportsIndex, Final, Literal as L
84+
from typing_extensions import SupportsIndex, final, Final, Literal as L
8585

8686
_SCT = TypeVar("_SCT", bound=generic)
8787
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
@@ -949,9 +949,31 @@ def compare_chararrays(
949949

950950
def add_docstring(__obj: Callable[..., Any], __docstring: str) -> None: ...
951951

952+
_GetItemKeys = L[
953+
"C", "CONTIGUOUS", "C_CONTIGUOUS",
954+
"F", "FORTRAN", "F_CONTIGUOUS",
955+
"W", "WRITEABLE",
956+
"B", "BEHAVED",
957+
"O", "OWNDATA",
958+
"A", "ALIGNED",
959+
"X", "WRITEBACKIFCOPY",
960+
"CA", "CARRAY",
961+
"FA", "FARRAY",
962+
"FNC",
963+
"FORC",
964+
]
965+
_SetItemKeys = L[
966+
"A", "ALIGNED",
967+
"W", "WRITABLE",
968+
"X", "WRITEBACKIFCOPY",
969+
]
970+
971+
@final
952972
class flagsobj:
973+
__hash__: None # type: ignore[assignment]
953974
aligned: bool
954-
updateifcopy: bool
975+
# NOTE: deprecated
976+
# updateifcopy: bool
955977
writeable: bool
956978
writebackifcopy: bool
957979
@property
@@ -976,5 +998,5 @@ class flagsobj:
976998
def num(self) -> int: ...
977999
@property
9781000
def owndata(self) -> bool: ...
979-
def __getitem__(self, key: str) -> bool: ...
980-
def __setitem__(self, key: str, value: bool) -> None: ...
1001+
def __getitem__(self, key: _GetItemKeys) -> bool: ...
1002+
def __setitem__(self, key: _SetItemKeys, value: bool) -> None: ...

0 commit comments

Comments
 (0)