Skip to content

Commit ec93791

Browse files
committed
Use mypy
1 parent 05593fd commit ec93791

15 files changed

+1713
-1562
lines changed

.github/workflows/mypy.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Type Checking
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
mypy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.10'
16+
- name: Install uv
17+
run: pip install uv
18+
- name: Create venv
19+
run: uv venv
20+
- name: Install dependencies
21+
run: |
22+
uv sync
23+
- name: Run Mypy
24+
run: uv run mypy .

pyproject.toml

+55-43
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ dependencies = [
2323
"numpy>=1,<2",
2424
]
2525

26-
[project.optional-dependencies]
27-
dev = [
28-
"ruff>=0.6.9",
29-
"pyright>=1.1.384",
30-
"pytest>=8.3.3",
31-
"langchain>=0.3.3",
32-
"langchain-openai>=0.2.2",
33-
"langchain-community>=0.3.2",
34-
"pandas>=2.2.3",
35-
"pytest-asyncio>=0.24.0",
36-
]
37-
3826
[project.urls]
3927
repository = "https://github.com/timescale/python-vector"
4028
documentation = "https://timescale.github.io/python-vector"
@@ -51,36 +39,46 @@ addopts = [
5139
"--import-mode=importlib",
5240
]
5341

54-
[tool.pyright]
55-
typeCheckingMode = "strict"
56-
reportImplicitOverride = true
57-
exclude = [
58-
"**/.bzr",
59-
"**/.direnv",
60-
"**/.eggs",
61-
"**/.git",
62-
"**/.git-rewrite",
63-
"**/.hg",
64-
"**/.ipynb_checkpoints",
65-
"**/.mypy_cache",
66-
"**/.nox",
67-
"**/.pants.d",
68-
"**/.pyenv",
69-
"**/.pytest_cache",
70-
"**/.pytype",
71-
"**/.ruff_cache",
72-
"**/.svn",
73-
"**/.tox",
74-
"**/.venv",
75-
"**/.vscode",
76-
"**/__pypackages__",
77-
"**/_build",
78-
"**/buck-out",
79-
"**/dist",
80-
"**/node_modules",
81-
"**/site-packages",
82-
"**/venv",
83-
]
42+
43+
[tool.mypy]
44+
strict = true
45+
ignore_missing_imports = true
46+
namespace_packages = true
47+
48+
49+
#[tool.pyright]
50+
#reportMissingTypeStubs = false
51+
#exclude = [
52+
# "**/.bzr",
53+
# "**/.direnv",
54+
# "**/.eggs",
55+
# "**/.git",
56+
# "**/.git-rewrite",
57+
# "**/.hg",
58+
# "**/.ipynb_checkpoints",
59+
# "**/.mypy_cache",
60+
# "**/.nox",
61+
# "**/.pants.d",
62+
# "**/.pyenv",
63+
# "**/.pytest_cache",
64+
# "**/.pytype",
65+
# "**/.ruff_cache",
66+
# "**/.svn",
67+
# "**/.tox",
68+
# "**/.venv",
69+
# "**/.vscode",
70+
# "**/__pypackages__",
71+
# "**/_build",
72+
# "**/buck-out",
73+
# "**/dist",
74+
# "**/node_modules",
75+
# "**/site-packages",
76+
# "**/venv",
77+
#]
78+
79+
#[[tool.pyright.overrides]]
80+
#source = ["**/*.py"]
81+
#ignore = ["asyncpg", "pgvector.psycopg2", "psycopg2", "asyncpg.*"]
8482

8583
[tool.ruff]
8684
line-length = 120
@@ -137,4 +135,18 @@ select = [
137135
"W291",
138136
"PIE",
139137
"Q"
140-
]
138+
]
139+
140+
[tool.uv]
141+
dev-dependencies = [
142+
"mypy>=1.12.0",
143+
"types-psycopg2>=2.9.21.20240819",
144+
"ruff>=0.6.9",
145+
"pyright>=1.1.384",
146+
"pytest>=8.3.3",
147+
"langchain>=0.3.3",
148+
"langchain-openai>=0.2.2",
149+
"langchain-community>=0.3.2",
150+
"pandas>=2.2.3",
151+
"pytest-asyncio>=0.24.0",
152+
]

tests/async_client_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async def test_vector(service_url: str, schema: str) -> None:
306306
assert not await vec.table_is_empty()
307307

308308
# check all the possible ways to specify a date range
309-
async def search_date(start_date, end_date, expected):
309+
async def search_date(start_date: datetime | str | None, end_date: datetime | str | None, expected: int) -> None:
310310
# using uuid_time_filter
311311
rec = await vec.search(
312312
[1.0, 2.0],

tests/pg_vectorizer_test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import timedelta
2+
from typing import Any
23

34
import psycopg2
45
import pytest
@@ -11,7 +12,7 @@
1112
from timescale_vector.pgvectorizer import Vectorize
1213

1314

14-
def get_document(blog):
15+
def get_document(blog: dict[str, Any]) -> list[Document]:
1516
text_splitter = CharacterTextSplitter(
1617
chunk_size=1000,
1718
chunk_overlap=200,
@@ -56,7 +57,7 @@ def test_pg_vectorizer(service_url: str) -> None:
5657
VALUES ('first', 'mat', 'first_post', 'personal', '2021-01-01');
5758
""")
5859

59-
def embed_and_write(blog_instances, vectorizer):
60+
def embed_and_write(blog_instances: list[Any], vectorizer: Vectorize) -> None:
6061
TABLE_NAME = vectorizer.table_name_unquoted + "_embedding"
6162
embedding = OpenAIEmbeddings()
6263
vector_store = TimescaleVector(

tests/sync_client_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ def test_sync_client(service_url: str, schema: str) -> None:
136136

137137
rec = vec.search([1.0, 2.0], filter={"key_1": "val_1", "key_2": "val_2"})
138138
assert rec[0][SEARCH_RESULT_CONTENTS_IDX] == "the brown fox"
139-
assert rec[0]["contents"] == "the brown fox"
139+
assert rec[0]["contents"] == "the brown fox" # type: ignore
140140
assert rec[0][SEARCH_RESULT_METADATA_IDX] == {
141141
"key_1": "val_1",
142142
"key_2": "val_2",
143143
}
144-
assert rec[0]["metadata"] == {"key_1": "val_1", "key_2": "val_2"}
144+
assert rec[0]["metadata"] == {"key_1": "val_1", "key_2": "val_2"} # type: ignore
145145
assert isinstance(rec[0][SEARCH_RESULT_METADATA_IDX], dict)
146146
assert rec[0][SEARCH_RESULT_DISTANCE_IDX] == 0.0009438353921149556
147-
assert rec[0]["distance"] == 0.0009438353921149556
147+
assert rec[0]["distance"] == 0.0009438353921149556 # type: ignore
148148

149149
rec = vec.search([1.0, 2.0], limit=4, predicates=Predicates("key", "==", "val2"))
150150
assert len(rec) == 1
@@ -218,7 +218,7 @@ def test_sync_client(service_url: str, schema: str) -> None:
218218
]
219219
)
220220

221-
def search_date(start_date, end_date, expected):
221+
def search_date(start_date: datetime | str | None, end_date: datetime | str | None, expected: int) -> None:
222222
# using uuid_time_filter
223223
rec = vec.search(
224224
[1.0, 2.0],

0 commit comments

Comments
 (0)