Skip to content

Commit 23d287a

Browse files
committed
Improved typing [skip ci]
1 parent d2a5fb0 commit 23d287a

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

pgvector/bit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
from struct import pack, unpack_from
3+
from typing import cast
34

45
try:
56
import numpy as np
@@ -60,7 +61,7 @@ def __eq__(self, other: object) -> bool:
6061

6162
def _length(self) -> int:
6263
length, = unpack_from('>i', self._value)
63-
return length
64+
return cast(int, length)
6465

6566
def to_list(self) -> list[bool]:
6667
# TODO improve

pgvector/halfvec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
import struct
3+
from typing import cast
34

45
try:
56
import numpy as np
@@ -38,7 +39,7 @@ def __eq__(self, other: object) -> bool:
3839

3940
def dimensions(self) -> int:
4041
dim, = struct.unpack_from('>H', self._value)
41-
return dim
42+
return cast(int, dim)
4243

4344
def to_list(self) -> list[float]:
4445
return list(struct.unpack_from(f'>{self.dimensions()}e', self._value[4:]))

pgvector/vector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
import struct
3+
from typing import cast
34

45
try:
56
import numpy as np
@@ -38,7 +39,7 @@ def __eq__(self, other: object) -> bool:
3839

3940
def dimensions(self) -> int:
4041
dim, = struct.unpack_from('>H', self._value)
41-
return dim
42+
return cast(int, dim)
4243

4344
def to_list(self) -> list[float]:
4445
return list(struct.unpack_from(f'>{self.dimensions()}f', self._value[4:]))

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ files = [
4646
"tests"
4747
]
4848
strict = true
49-
disable_error_code = ["unused-ignore"]
49+
disable_error_code = ["unused-ignore", "no-untyped-def", "no-untyped-call"]
5050
ignore_missing_imports = true
51+
disallow_subclassing_any = false
5152
python_executable = ".venv/bin/python"
5253

5354
[tool.pyright]

0 commit comments

Comments
 (0)