Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Configures pyright to ignore invalid type forms
Temporarily disables `reportInvalidTypeForm` in pyright configuration due to ongoing transition to the new type system in numpy 2.2.x.
  • Loading branch information
robbiemu committed May 19, 2025
commit 6ee825381b5cdecedb42d4ca5b43d1cf4d09f2c1
2 changes: 0 additions & 2 deletions gguf-py/gguf/gguf_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pyright: reportInvalidTypeForm=false
#
# GGUF file reading/modification support. For API usage information,
# please see the files scripts/ for some fairly simple examples.
#
Expand Down Expand Up @@ -136,12 +134,12 @@
offs = 0

# Check for GGUF magic
if self._get(offs, np.uint32, override_order = '<')[0] != GGUF_MAGIC:

Check failure on line 137 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint32" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
raise ValueError('GGUF magic invalid')
offs += 4

# Check GGUF version
temp_version = self._get(offs, np.uint32)

Check failure on line 142 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint32" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
if temp_version[0] & 65535 == 0:
# If we get 0 here that means it's (probably) a GGUF file created for
# the opposite byte order of the machine this script is running on.
Expand All @@ -164,7 +162,7 @@
offs += self._push_field(ReaderField(offs, 'GGUF.version', [temp_version], [0], [GGUFValueType.UINT32]))

# Check tensor count and kv count
temp_counts = self._get(offs, np.uint64, 2)

Check failure on line 165 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint64" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
offs += self._push_field(ReaderField(offs, 'GGUF.tensor_count', [temp_counts[:1]], [0], [GGUFValueType.UINT64]))
offs += self._push_field(ReaderField(offs, 'GGUF.kv_count', [temp_counts[1:]], [0], [GGUFValueType.UINT64]))
tensor_count, kv_count = temp_counts
Expand Down Expand Up @@ -214,8 +212,8 @@
return 0 if skip_sum else sum(int(part.nbytes) for part in field.parts)

def _get_str(self, offset: int) -> tuple[npt.NDArray[np.uint64], npt.NDArray[np.uint8]]:
slen = self._get(offset, np.uint64)

Check failure on line 215 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint64" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
return slen, self._get(offset + 8, np.uint8, slen[0].item())

Check failure on line 216 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint8" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)

def _get_field_parts(
self, orig_offs: int, raw_type: int,
Expand All @@ -236,9 +234,9 @@
return int(val.nbytes), [val], [0], types
# Handle arrays.
if gtype == GGUFValueType.ARRAY:
raw_itype = self._get(offs, np.uint32)

Check failure on line 237 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint32" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
offs += int(raw_itype.nbytes)
alen = self._get(offs, np.uint64)

Check failure on line 239 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint64" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
offs += int(alen.nbytes)
aparts: list[npt.NDArray[Any]] = [raw_itype, alen]
data_idxs: list[int] = []
Expand All @@ -263,7 +261,7 @@
offs += int(name_len.nbytes + name_data.nbytes)

# Get Tensor Dimensions Count
n_dims = self._get(offs, np.uint32)

Check failure on line 264 in gguf-py/gguf/gguf_reader.py

View workflow job for this annotation

GitHub Actions / pyright type-check

Argument of type "uint32" cannot be assigned to parameter "dtype" of type "dtype[Any]" in function "_get"   "type[type]" is not assignable to "type[dtype[Any]]" (reportArgumentType)
offs += int(n_dims.nbytes)

# Get Tensor Dimension Array
Expand Down
1 change: 1 addition & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extraPaths": ["gguf-py"],
"pythonVersion": "3.10",
"pythonPlatform": "All",
"reportInvalidTypeForm": false, // TODO: remove once numpy 2.2.x resolves the transition to their new type system
"reportUnusedImport": "warning",
"reportDuplicateImport": "error",
"reportDeprecated": "warning",
Expand Down
Loading