Skip to content

Commit c1d00b0

Browse files
committed
Fixed typechecking for Python 3.10 [skip ci]
1 parent c892874 commit c1d00b0

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

pgvector/bit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class Bit:
12-
def __init__(self, value: bytes | str | list[bool] | np.ndarray[tuple[int], np.dtype[np.bool | np.uint8]]) -> None:
12+
def __init__(self, value: bytes | str | list[bool] | np.ndarray[tuple[int, ...], np.dtype[np.bool | np.uint8]]) -> None:
1313
if isinstance(value, bytes):
1414
self._length = 8 * len(value)
1515
self._data = value
@@ -44,7 +44,7 @@ def bit_value(v: bool) -> str:
4444
raise ValueError('expected ndim to be 1')
4545

4646
self._length = len(value)
47-
self._data = np.packbits(value).tobytes()
47+
self._data = np.packbits(value).tobytes() # type: ignore
4848
else:
4949
raise ValueError('expected bytes, str, list, or ndarray')
5050

@@ -60,7 +60,7 @@ def to_list(self) -> list[bool]:
6060
# TODO improve
6161
return [v != '0' for v in self.to_text()]
6262

63-
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.bool]]:
63+
def to_numpy(self) -> np.ndarray[tuple[int, ...], np.dtype[np.bool]]:
6464
return np.unpackbits(np.frombuffer(self._data, dtype=np.uint8), count=self._length).astype(bool)
6565

6666
def to_text(self) -> str:

pgvector/django/extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
class VectorExtension(CreateExtension):
77
def __init__(self, hints: Any = None) -> None:
88
if VERSION[0] >= 6:
9-
super().__init__('vector', hints=hints)
9+
super().__init__('vector', hints=hints) # type: ignore
1010
else:
1111
self.name = 'vector'

pgvector/halfvec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class HalfVector:
14-
def __init__(self, value: list[float] | np.ndarray[tuple[int], np.dtype[np.floating]]) -> None:
14+
def __init__(self, value: list[float] | np.ndarray[tuple[int, ...], np.dtype[np.floating]]) -> None:
1515
if isinstance(value, list):
1616
dim = len(value)
1717
try:
@@ -43,7 +43,7 @@ def to_list(self) -> list[float]:
4343
dim = len(self._value)
4444
return list(struct.unpack(f'{dim}e', self._value))
4545

46-
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.float16]]:
46+
def to_numpy(self) -> np.ndarray[tuple[int, ...], np.dtype[np.float16]]:
4747
return np.frombuffer(self._value, dtype=np.float16)
4848

4949
def to_text(self) -> str:

pgvector/psycopg/vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class VectorDumper(Dumper):
1919
format = Format.TEXT
2020

21-
def dump(self, obj: 'Vector | np.ndarray') -> Buffer | None:
21+
def dump(self, obj: 'Vector | np.ndarray[tuple[int, ...], np.dtype[np.floating]]') -> Buffer | None:
2222
if not isinstance(obj, Vector):
2323
obj = Vector(obj)
2424
return obj.to_text().encode('utf8')
@@ -27,7 +27,7 @@ def dump(self, obj: 'Vector | np.ndarray') -> Buffer | None:
2727
class VectorBinaryDumper(VectorDumper):
2828
format = Format.BINARY
2929

30-
def dump(self, obj: 'Vector | np.ndarray') -> Buffer | None:
30+
def dump(self, obj: 'Vector | np.ndarray[tuple[int, ...], np.dtype[np.floating]]') -> Buffer | None:
3131
if not isinstance(obj, Vector):
3232
obj = Vector(obj)
3333
return obj.to_binary()

pgvector/psycopg2/vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class VectorAdapter:
13-
def __init__(self, value: 'Vector | np.ndarray') -> None:
13+
def __init__(self, value: 'Vector | np.ndarray[tuple[int, ...], np.dtype[np.floating]]') -> None:
1414
if not isinstance(value, Vector):
1515
value = Vector(value)
1616
self._value = value

pgvector/sparsevec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def __init__(self, value: dict[int, float], dimensions: int, /) -> None:
2222
...
2323

2424
@overload
25-
def __init__(self, value: list[float] | np.ndarray[tuple[int], np.dtype[np.floating]] | sparray | spmatrix, /) -> None:
25+
def __init__(self, value: list[float] | np.ndarray[tuple[int, ...], np.dtype[np.floating]] | sparray | spmatrix, /) -> None:
2626
...
2727

28-
def __init__(self, value: dict[int, float] | list[float] | np.ndarray[tuple[int], np.dtype[np.floating]] | sparray | spmatrix, dimensions: int | Any = NO_DEFAULT, /) -> None:
28+
def __init__(self, value: dict[int, float] | list[float] | np.ndarray[tuple[int, ...], np.dtype[np.floating]] | sparray | spmatrix, dimensions: int | Any = NO_DEFAULT, /) -> None:
2929
if SCIPY_AVAILABLE and isinstance(value, (sparray, spmatrix)):
3030
if dimensions is not NO_DEFAULT:
3131
raise ValueError('extra argument')
@@ -70,7 +70,7 @@ def to_list(self) -> list[float]:
7070
vec[i] = v
7171
return vec
7272

73-
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.float32]]:
73+
def to_numpy(self) -> np.ndarray[tuple[int, ...], np.dtype[np.float32]]:
7474
vec = np.repeat(0.0, self._dim).astype(np.float32)
7575
for i, v in zip(self._indices, self._values):
7676
vec[i] = v

pgvector/vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class Vector:
14-
def __init__(self, value: list[float] | np.ndarray[tuple[int], np.dtype[np.floating]]) -> None:
14+
def __init__(self, value: list[float] | np.ndarray[tuple[int, ...], np.dtype[np.floating]]) -> None:
1515
if isinstance(value, list):
1616
try:
1717
self._value = array.array('f', value)
@@ -41,7 +41,7 @@ def dimensions(self) -> int:
4141
def to_list(self) -> list[float]:
4242
return self._value.tolist()
4343

44-
def to_numpy(self) -> np.ndarray[tuple[int], np.dtype[np.float32]]:
44+
def to_numpy(self) -> np.ndarray[tuple[int, ...], np.dtype[np.float32]]:
4545
return np.frombuffer(self._value, dtype=np.float32)
4646

4747
def to_text(self) -> str:

0 commit comments

Comments
 (0)