Skip to content

Commit

Permalink
fix: use mypy instead of pyright and fix all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Askir committed Oct 18, 2024
1 parent a7d9aab commit 1df8ac8
Show file tree
Hide file tree
Showing 15 changed files with 1,676 additions and 1,585 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Type Checking

on:
pull_request:
branches: [ main ]

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install uv
run: pip install uv
- name: Create venv
run: uv venv
- name: Install dependencies
run: |
uv sync
- name: Run Mypy
run: uv run mypy .
62 changes: 19 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ dependencies = [
"numpy>=1,<2",
]

[project.optional-dependencies]
dev = [
"ruff>=0.6.9",
"pyright>=1.1.384",
"pytest>=8.3.3",
"langchain>=0.3.3",
"langchain-openai>=0.2.2",
"langchain-community>=0.3.2",
"pandas>=2.2.3",
"pytest-asyncio>=0.24.0",
]

[project.urls]
repository = "https://github.com/timescale/python-vector"
documentation = "https://timescale.github.io/python-vector"
Expand All @@ -51,36 +39,11 @@ addopts = [
"--import-mode=importlib",
]

[tool.pyright]
typeCheckingMode = "strict"
reportImplicitOverride = true
exclude = [
"**/.bzr",
"**/.direnv",
"**/.eggs",
"**/.git",
"**/.git-rewrite",
"**/.hg",
"**/.ipynb_checkpoints",
"**/.mypy_cache",
"**/.nox",
"**/.pants.d",
"**/.pyenv",
"**/.pytest_cache",
"**/.pytype",
"**/.ruff_cache",
"**/.svn",
"**/.tox",
"**/.venv",
"**/.vscode",
"**/__pypackages__",
"**/_build",
"**/buck-out",
"**/dist",
"**/node_modules",
"**/site-packages",
"**/venv",
]

[tool.mypy]
strict = true
ignore_missing_imports = true
namespace_packages = true

[tool.ruff]
line-length = 120
Expand Down Expand Up @@ -137,4 +100,17 @@ select = [
"W291",
"PIE",
"Q"
]
]

[tool.uv]
dev-dependencies = [
"mypy>=1.12.0",
"types-psycopg2>=2.9.21.20240819",
"ruff>=0.6.9",
"pytest>=8.3.3",
"langchain>=0.3.3",
"langchain-openai>=0.2.2",
"langchain-community>=0.3.2",
"pandas>=2.2.3",
"pytest-asyncio>=0.24.0",
]
2 changes: 1 addition & 1 deletion tests/async_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async def test_vector(service_url: str, schema: str) -> None:
assert not await vec.table_is_empty()

# check all the possible ways to specify a date range
async def search_date(start_date, end_date, expected):
async def search_date(start_date: datetime | str | None, end_date: datetime | str | None, expected: int) -> None:
# using uuid_time_filter
rec = await vec.search(
[1.0, 2.0],
Expand Down
5 changes: 3 additions & 2 deletions tests/pg_vectorizer_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from typing import Any

import psycopg2
import pytest
Expand All @@ -11,7 +12,7 @@
from timescale_vector.pgvectorizer import Vectorize


def get_document(blog):
def get_document(blog: dict[str, Any]) -> list[Document]:
text_splitter = CharacterTextSplitter(
chunk_size=1000,
chunk_overlap=200,
Expand Down Expand Up @@ -56,7 +57,7 @@ def test_pg_vectorizer(service_url: str) -> None:
VALUES ('first', 'mat', 'first_post', 'personal', '2021-01-01');
""")

def embed_and_write(blog_instances, vectorizer):
def embed_and_write(blog_instances: list[Any], vectorizer: Vectorize) -> None:
TABLE_NAME = vectorizer.table_name_unquoted + "_embedding"
embedding = OpenAIEmbeddings()
vector_store = TimescaleVector(
Expand Down
8 changes: 4 additions & 4 deletions tests/sync_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ def test_sync_client(service_url: str, schema: str) -> None:

rec = vec.search([1.0, 2.0], filter={"key_1": "val_1", "key_2": "val_2"})
assert rec[0][SEARCH_RESULT_CONTENTS_IDX] == "the brown fox"
assert rec[0]["contents"] == "the brown fox"
assert rec[0]["contents"] == "the brown fox" # type: ignore
assert rec[0][SEARCH_RESULT_METADATA_IDX] == {
"key_1": "val_1",
"key_2": "val_2",
}
assert rec[0]["metadata"] == {"key_1": "val_1", "key_2": "val_2"}
assert rec[0]["metadata"] == {"key_1": "val_1", "key_2": "val_2"} # type: ignore
assert isinstance(rec[0][SEARCH_RESULT_METADATA_IDX], dict)
assert rec[0][SEARCH_RESULT_DISTANCE_IDX] == 0.0009438353921149556
assert rec[0]["distance"] == 0.0009438353921149556
assert rec[0]["distance"] == 0.0009438353921149556 # type: ignore

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

def search_date(start_date, end_date, expected):
def search_date(start_date: datetime | str | None, end_date: datetime | str | None, expected: int) -> None:
# using uuid_time_filter
rec = vec.search(
[1.0, 2.0],
Expand Down
Loading

0 comments on commit 1df8ac8

Please sign in to comment.