Skip to content

Commit 66c4515

Browse files
committed
Improved type hints [skip ci]
1 parent 09a9837 commit 66c4515

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pgvector/bit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22
import numpy as np
33
from struct import pack, unpack_from
4-
from typing import Any
54
from warnings import warn
65

76

87
class Bit:
9-
def __init__(self, value: Any) -> None:
8+
def __init__(self, value: object) -> None:
109
if isinstance(value, bytes):
1110
self._len = 8 * len(value)
1211
self._data = value
@@ -16,12 +15,18 @@ def __init__(self, value: Any) -> None:
1615
else:
1716
value = np.asarray(value)
1817

18+
# for mypy
19+
assert isinstance(value, np.ndarray)
20+
1921
if value.dtype != np.bool:
2022
# skip warning for result of np.unpackbits
2123
if value.dtype != np.uint8 or np.any(value > 1):
2224
warn('expected elements to be boolean', stacklevel=2)
2325
value = value.astype(bool)
2426

27+
# for mypy
28+
assert isinstance(value, np.ndarray)
29+
2530
if value.ndim != 1:
2631
raise ValueError('expected ndim to be 1')
2732

0 commit comments

Comments
 (0)