Skip to content

Commit 63a2f9e

Browse files
committed
chore(ollama): switch to ty
1 parent acc29cc commit 63a2f9e

File tree

6 files changed

+37
-81
lines changed

6 files changed

+37
-81
lines changed

libs/partners/ollama/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ integration_test:
3737

3838
# Define a variable for Python and notebook files.
3939
PYTHON_FILES=.
40-
MYPY_CACHE=.mypy_cache
4140
lint format: PYTHON_FILES=.
4241
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/ollama --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
4342
lint_package: PYTHON_FILES=langchain_ollama
4443
lint_tests: PYTHON_FILES=tests
45-
lint_tests: MYPY_CACHE=.mypy_cache_test
4644
UV_RUN_LINT = uv run --all-groups
47-
UV_RUN_TYPE = uv run --all-groups
4845
lint_package lint_tests: UV_RUN_LINT = uv run --group lint
4946

5047
lint lint_diff lint_package lint_tests:
5148
./scripts/lint_imports.sh
5249
[ "$(PYTHON_FILES)" = "" ] || $(UV_RUN_LINT) ruff check $(PYTHON_FILES)
5350
[ "$(PYTHON_FILES)" = "" ] || $(UV_RUN_LINT) ruff format $(PYTHON_FILES) --diff
54-
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && $(UV_RUN_TYPE) mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
51+
$(MAKE) type
5552

5653
type:
57-
mkdir -p $(MYPY_CACHE) && $(UV_RUN_TYPE) mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
54+
uv run --all-groups ty check langchain_ollama
5855

5956
format format_diff:
6057
[ "$(PYTHON_FILES)" = "" ] || $(UV_RUN_LINT) ruff format $(PYTHON_FILES)

libs/partners/ollama/langchain_ollama/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

1616
from importlib import metadata
1717
from importlib.metadata import PackageNotFoundError
18+
from typing import NoReturn
1819

1920
from langchain_ollama.chat_models import ChatOllama
2021
from langchain_ollama.embeddings import OllamaEmbeddings
2122
from langchain_ollama.llms import OllamaLLM
2223

2324

24-
def _raise_package_not_found_error() -> None:
25+
def _raise_package_not_found_error() -> NoReturn:
2526
raise PackageNotFoundError
2627

2728

libs/partners/ollama/langchain_ollama/chat_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ class AnswerWithJustification(BaseModel):
15391539
)
15401540
if is_pydantic_schema:
15411541
output_parser: Runnable = PydanticToolsParser(
1542-
tools=[schema], # type: ignore[list-item]
1542+
tools=[schema], # ty: ignore[invalid-argument-type]
15431543
first_tool_only=True,
15441544
)
15451545
else:
@@ -1555,7 +1555,7 @@ class AnswerWithJustification(BaseModel):
15551555
},
15561556
)
15571557
output_parser = (
1558-
PydanticOutputParser(pydantic_object=schema) # type: ignore[arg-type]
1558+
PydanticOutputParser(pydantic_object=schema) # ty: ignore[invalid-argument-type]
15591559
if is_pydantic_schema
15601560
else JsonOutputParser()
15611561
)
@@ -1579,7 +1579,7 @@ class AnswerWithJustification(BaseModel):
15791579
"schema": schema,
15801580
},
15811581
)
1582-
output_parser = PydanticOutputParser(pydantic_object=schema) # type: ignore[arg-type]
1582+
output_parser = PydanticOutputParser(pydantic_object=schema)
15831583
else:
15841584
if is_typeddict(schema):
15851585
response_format = convert_to_json_schema(schema)

libs/partners/ollama/langchain_ollama/llms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def _generate(
475475
**kwargs,
476476
)
477477
generations.append([final_chunk])
478-
return LLMResult(generations=generations) # type: ignore[arg-type]
478+
return LLMResult(generations=generations)
479479

480480
async def _agenerate(
481481
self,
@@ -494,7 +494,7 @@ async def _agenerate(
494494
**kwargs,
495495
)
496496
generations.append([final_chunk])
497-
return LLMResult(generations=generations) # type: ignore[arg-type]
497+
return LLMResult(generations=generations)
498498

499499
def _stream(
500500
self,

libs/partners/ollama/pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test_integration = []
5151
lint = ["ruff>=0.13.1,<0.14.0"]
5252
dev = ["langchain-core"]
5353
typing = [
54-
"mypy>=1.17.1,<2.0.0",
54+
"ty>=0.0.1,<1.0.0",
5555
"langchain-core"
5656
]
5757

@@ -62,9 +62,6 @@ constraint-dependencies = ["pygments>=2.20.0"]
6262
langchain-core = { path = "../../core", editable = true }
6363
langchain-tests = { path = "../../standard-tests", editable = true }
6464

65-
[tool.mypy]
66-
disallow_untyped_defs = "True"
67-
6865
[tool.ruff.format]
6966
docstring-code-format = true
7067
docstring-code-line-length = 100

0 commit comments

Comments
 (0)