8000 TYP: Deprecate calling ``numpy.save`` with ``fix_imports`` (PEP 702) · numpy/numpy@be72b3d · GitHub
[go: up one dir, main page]

Skip to content

Commit be72b3d

Browse files
committed
TYP: Deprecate calling numpy.save with fix_imports (PEP 702)
1 parent be296e2 commit be72b3d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

numpy/lib/_npyio_impl.pyi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from typing import (
1313
overload,
1414
Protocol,
1515
)
16+
from typing_extensions import deprecated
1617

1718
from numpy import (
1819
ndarray,
@@ -129,11 +130,29 @@ def load(
129130
encoding: L["ASCII", "latin1", "bytes"] = ...,
130131
) -> Any: ...
131132

133+
@overload
132134
def save(
133135
file: str | os.PathLike[str] | _SupportsWrite[bytes],
134136
arr: ArrayLike,
135137
allow_pickle: bool = ...,
136-
fix_imports: bool = ...,
138+
) -> None: ...
139+
@overload
140+
@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.")
141+
def save(
142+
file: str | os.PathLike[str] | _SupportsWrite[bytes],
143+
arr: ArrayLike,
144+
allow_pickle: bool = ...,
145+
*,
146+
fix_imports: bool,
147+
) -> None: ...
148+
@overload
149+
@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.")
150+
def save(
151+
file: str | os.PathLike[str] | _SupportsWrite[bytes],
152+
arr: ArrayLike,
153+
allow_pickle: bool,
154+
fix_imports: bool,
155+
/,
137156
) -> None: ...
138157

139158
def savez(

numpy/typing/tests/data/fail/npyio.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ AR_i8: npt.NDArray[np.int64]
1212

1313
np.load(str_file) # E: incompatible type
1414

15-
np.save(bytes_path, AR_i8) # E: incompatible type
15+
np.save(bytes_path, AR_i8) # E: No overload variant
16+
# https://github.com/python/mypy/issues/16111
17+
# np.save(str_path, AR_i8, fix_imports=True) # W: deprecated
1618

1719
np.savez(bytes_path, AR_i8) # E: incompatible type
1820

0 commit comments

Comments
 (0)
0