Skip to content

Commit eb7cef1

Browse files
committed
Updates type hints for numpy compatibility
Updates type hints related to numpy to use `np.dtype[Any]` instead of `DTypeLike` for better compatibility and clarity. This resolves potential issues with type checking and ensures accurate type annotations for numpy-related operations within the `gguf` library.
1 parent a6ab097 commit eb7cef1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

gguf-py/gguf/lazy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any, Callable
66

77
import numpy as np
8-
from numpy.typing import DTypeLike
98

109

1110
logger = logging.getLogger(__name__)
@@ -107,7 +106,7 @@ def _recurse_apply(o: Any, fn: Callable[[Any], Any]) -> Any:
107106
return o
108107

109108
@classmethod
110-
def _wrap_fn(cls, fn: Callable, *, use_self: LazyBase | None = None, meta_noop: bool | DTypeLike | tuple[DTypeLike, Callable[[tuple[int, ...]], tuple[int, ...]]] = False) -> Callable[[Any], Any]:
109+
def _wrap_fn(cls, fn: Callable, *, use_self: LazyBase | None = None, meta_noop: bool | np.dtype[Any] | tuple[np.dtype[Any], Callable[[tuple[int, ...]], tuple[int, ...]]] = False) -> Callable[[Any], Any]:
111110
def wrapped_fn(*args, **kwargs):
112111
if kwargs is None:
113112
kwargs = {}
@@ -204,7 +203,7 @@ class LazyNumpyTensor(LazyBase):
204203
shape: tuple[int, ...] # Makes the type checker happy in quants.py
205204

206205
@classmethod
207-
def meta_with_dtype_and_shape(cls, dtype: DTypeLike, shape: tuple[int, ...]) -> np.ndarray[Any, Any]:
206+
def meta_with_dtype_and_shape(cls, dtype: np.dtype[Any], shape: tuple[int, ...]) -> np.ndarray[Any, Any]:
208207
# The initial idea was to use np.nan as the fill value,
209208
# but non-float types like np.int16 can't use that.
210209
# So zero it is.

0 commit comments

Comments
 (0)