Skip to content

Commit 9b8cb71

Browse files
authored
uprev pyright, fix typing (#1283)
1 parent d863466 commit 9b8cb71

File tree

14 files changed

+57
-33
lines changed

14 files changed

+57
-33
lines changed

mcp-run-python/src/prepare_env.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from __future__ import annotations as _annotations
77

88
import importlib
9-
import importlib.util
109
import logging
1110
import re
1211
import sys

pydantic_ai_slim/pydantic_ai/_result.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def __init__(self, response_type: type[ResultDataT], name: str, description: str
161161
# noinspection PyArgumentList
162162
parameters_json_schema = _utils.check_object_json_schema(self.type_adapter.json_schema())
163163
else:
164-
response_data_typed_dict = TypedDict('response_data_typed_dict', {'response': response_type}) # noqa
164+
response_data_typed_dict = TypedDict( # noqa: UP013
165+
'response_data_typed_dict',
166+
{'response': response_type}, # pyright: ignore[reportInvalidTypeForm]
167+
)
165168
self.type_adapter = TypeAdapter(response_data_typed_dict)
166169
outer_typed_dict_key = 'response'
167170
# noinspection PyArgumentList

pydantic_ai_slim/pydantic_ai/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def is_model_like(type_: Any) -> bool:
4040
return (
4141
isinstance(type_, type)
4242
and not isinstance(type_, GenericAlias)
43-
and (issubclass(type_, BaseModel) or is_dataclass(type_) or is_typeddict(type_))
43+
and (issubclass(type_, BaseModel) or is_dataclass(type_) or is_typeddict(type_)) # pyright: ignore[reportUnknownArgumentType]
4444
)
4545

4646

pydantic_ai_slim/pydantic_ai/agent.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ def __init__(
212212

213213
self._result_tool_name = result_tool_name
214214
self._result_tool_description = result_tool_description
215-
self._result_schema: _result.ResultSchema[ResultDataT] | None = _result.ResultSchema[result_type].build(
215+
self._result_schema = _result.ResultSchema[result_type].build(
216216
result_type, result_tool_name, result_tool_description
217217
)
218-
self._result_validators: list[_result.ResultValidator[AgentDepsT, ResultDataT]] = []
218+
self._result_validators = []
219219

220220
self._system_prompts = (system_prompt,) if isinstance(system_prompt, str) else tuple(system_prompt)
221-
self._system_prompt_functions: list[_system_prompt.SystemPromptRunner[AgentDepsT]] = []
222-
self._system_prompt_dynamic_functions: dict[str, _system_prompt.SystemPromptRunner[AgentDepsT]] = {}
221+
self._system_prompt_functions = []
222+
self._system_prompt_dynamic_functions = {}
223223

224-
self._function_tools: dict[str, Tool[AgentDepsT]] = {}
224+
self._function_tools = {}
225225

226226
self._default_retries = retries
227227
self._max_result_retries = result_retries if result_retries is not None else retries

pydantic_ai_slim/pydantic_ai/messages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pydantic
1111
import pydantic_core
12-
from opentelemetry._events import Event
12+
from opentelemetry._events import Event # pyright: ignore[reportPrivateImportUsage]
1313
from typing_extensions import TypeAlias
1414

1515
from ._utils import generate_tool_call_id as _generate_tool_call_id, now_utc as _now_utc

pydantic_ai_slim/pydantic_ai/models/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from dataclasses import dataclass, field
1313
from datetime import datetime
1414
from functools import cache
15-
from typing import TYPE_CHECKING, cast
15+
from typing import TYPE_CHECKING
1616

1717
import httpx
1818
from typing_extensions import Literal, TypeAliasType
@@ -386,7 +386,6 @@ def infer_model(model: Model | KnownModelName) -> Model:
386386

387387
try:
388388
provider, model_name = model.split(':', maxsplit=1)
389-
provider = cast(str, provider)
390389
except ValueError:
391390
model_name = model
392391
# TODO(Marcelo): We should deprecate this way.

pydantic_ai_slim/pydantic_ai/models/instrumented.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from typing import Any, Callable, Literal
88
from urllib.parse import urlparse
99

10-
from opentelemetry._events import Event, EventLogger, EventLoggerProvider, get_event_logger_provider
10+
from opentelemetry._events import (
11+
Event, # pyright: ignore[reportPrivateImportUsage]
12+
EventLogger, # pyright: ignore[reportPrivateImportUsage]
13+
EventLoggerProvider, # pyright: ignore[reportPrivateImportUsage]
14+
get_event_logger_provider, # pyright: ignore[reportPrivateImportUsage]
15+
)
1116
from opentelemetry.trace import Span, Tracer, TracerProvider, get_tracer_provider
1217
from opentelemetry.util.types import AttributeValue
1318
from pydantic import TypeAdapter

pydantic_evals/pydantic_evals/dataset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
else:
5555
from pathlib import Path
5656

57-
logfire._internal.stack_info.NON_USER_CODE_PREFIXES += (str(Path(__file__).parent.absolute()),)
57+
logfire._internal.stack_info.NON_USER_CODE_PREFIXES += (str(Path(__file__).parent.absolute()),) # pyright: ignore[reportPrivateImportUsage]
5858

5959
_logfire = logfire_api.Logfire(otel_scope='pydantic-evals')
6060

@@ -628,9 +628,9 @@ def _make_typed_dict(cls_name_prefix: str, fields: dict[str, Any]) -> Any:
628628

629629
class ClsDatasetRow(BaseModel, extra='forbid'):
630630
name: str
631-
inputs: in_type
632-
metadata: meta_type
633-
expected_output: out_type | None = None
631+
inputs: in_type # pyright: ignore[reportInvalidTypeForm]
632+
metadata: meta_type # pyright: ignore[reportInvalidTypeForm]
633+
expected_output: out_type | None = None # pyright: ignore[reportInvalidTypeForm,reportUnknownVariableType]
634634
if evaluator_schema_types:
635635
evaluators: list[Union[tuple(evaluator_schema_types)]] = [] # pyright: ignore # noqa UP007
636636

pydantic_evals/pydantic_evals/otel/_context_in_memory_span_exporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
try:
1616
from logfire._internal.tracer import (
17-
ProxyTracerProvider as LogfireProxyTracerProvider, # pyright: ignore[reportAssignmentType]
17+
ProxyTracerProvider as LogfireProxyTracerProvider, # pyright: ignore[reportAssignmentType,reportPrivateImportUsage]
1818
)
1919

2020
_LOGFIRE_IS_INSTALLED = True

pydantic_evals/pydantic_evals/otel/span_tree.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ def _matches(span: SpanNode, query: SpanQuery) -> bool: # noqa C901
416416
return False
417417

418418
# Timing conditions
419-
if (min_duration := query.get('min_duration')) is not None and span.duration is not None:
419+
if (min_duration := query.get('min_duration')) is not None and span.duration is not None: # pyright: ignore[reportUnnecessaryComparison]
420420
if not isinstance(min_duration, timedelta):
421421
min_duration = timedelta(seconds=min_duration)
422422
if span.duration < min_duration:
423423
return False
424-
if (max_duration := query.get('max_duration')) is not None and span.duration is not None:
424+
if (max_duration := query.get('max_duration')) is not None and span.duration is not None: # pyright: ignore[reportUnnecessaryComparison]
425425
if not isinstance(max_duration, timedelta):
426426
max_duration = timedelta(seconds=max_duration)
427427
if span.duration > max_duration:

pydantic_graph/pydantic_graph/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
else:
2828
from pathlib import Path
2929

30-
logfire._internal.stack_info.NON_USER_CODE_PREFIXES += (str(Path(__file__).parent.absolute()),)
30+
logfire._internal.stack_info.NON_USER_CODE_PREFIXES += (str(Path(__file__).parent.absolute()),) # pyright: ignore[reportPrivateImportUsage]
3131

3232

3333
__all__ = 'Graph', 'GraphRun', 'GraphRunResult'
@@ -111,7 +111,7 @@ def __init__(
111111
self.auto_instrument = auto_instrument
112112

113113
parent_namespace = _utils.get_parent_namespace(inspect.currentframe())
114-
self.node_defs: dict[str, NodeDef[StateT, DepsT, RunEndT]] = {}
114+
self.node_defs = {}
115115
for node in nodes:
116116
self._register_node(node, parent_namespace)
117117

pyproject.toml

+24-6
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ pydantic-ai-examples = { workspace = true }
6060
mcp-run-python = { workspace = true }
6161

6262
[tool.uv.workspace]
63-
members = ["pydantic_ai_slim", "pydantic_evals", "pydantic_graph", "mcp-run-python", "examples"]
63+
members = [
64+
"pydantic_ai_slim",
65+
"pydantic_evals",
66+
"pydantic_graph",
67+
"mcp-run-python",
68+
"examples",
69+
]
6470

6571
[dependency-groups]
6672
# dev dependencies are defined in `pydantic-ai-slim/pyproject.toml` to allow for minimal testing
67-
lint = ["mypy>=1.11.2", "pyright>=1.1.388,<1.1.390", "ruff>=0.6.9"]
73+
lint = ["mypy>=1.11.2", "pyright>=1.1.390", "ruff>=0.6.9"]
6874
docs = [
6975
"black>=24.10.0",
7076
"bs4>=0.0.2",
@@ -132,12 +138,24 @@ reportMissingTypeStubs = false
132138
reportUnnecessaryIsInstance = false
133139
reportUnnecessaryTypeIgnoreComment = true
134140
reportMissingModuleSource = false
135-
include = ["pydantic_ai_slim", "pydantic_evals", "pydantic_graph", "mcp-run-python", "examples", "tests"]
141+
include = [
142+
"pydantic_ai_slim",
143+
"pydantic_evals",
144+
"pydantic_graph",
145+
"mcp-run-python",
146+
"tests",
147+
"examples",
148+
]
136149
venvPath = ".venv"
137150
# see https://github.com/microsoft/pyright/issues/7771 - we don't want to error on decorated functions in tests
138151
# which are not otherwise used
139-
executionEnvironments = [{ root = "tests", reportUnusedFunction = false }]
140-
exclude = ["examples/pydantic_ai_examples/weather_agent_gradio.py", "mcp-run-python/node_modules"]
152+
executionEnvironments = [
153+
{ root = "tests", reportUnusedFunction = false, reportPrivateImportUsage = false },
154+
]
155+
exclude = [
156+
"examples/pydantic_ai_examples/weather_agent_gradio.py",
157+
"mcp-run-python/node_modules",
158+
]
141159
extraPaths = ["mcp-run-python/stubs"]
142160

143161
[tool.mypy]
@@ -154,7 +172,7 @@ filterwarnings = [
154172
"ignore::RuntimeWarning:pydantic_ai.mcp",
155173
# uvicorn (mcp server)
156174
"ignore:websockets.legacy is deprecated.*:DeprecationWarning:websockets.legacy",
157-
"ignore:websockets.server.WebSocketServerProtocol is deprecated:DeprecationWarning"
175+
"ignore:websockets.server.WebSocketServerProtocol is deprecated:DeprecationWarning",
158176
]
159177

160178
# https://coverage.readthedocs.io/en/latest/config.html#run

tests/json_body_serializer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ def serialize(cassette_dict: Any):
6363
content_type = headers.get('content-type', [])
6464
if any(isinstance(header, str) and header.startswith('application/json') for header in content_type):
6565
# Parse the body as JSON
66-
body: Any = data.get('body', None)
66+
body = data.get('body', None)
6767
assert body is not None, data
6868
if isinstance(body, dict):
6969
# Responses will have the body under a field called 'string'
7070
body = body.get('string')
7171
if body is not None:
72-
data['parsed_body'] = json.loads(body)
72+
data['parsed_body'] = json.loads(body) # pyright: ignore[reportUnknownArgumentType]
7373
if 'access_token' in data['parsed_body']:
7474
data['parsed_body']['access_token'] = 'scrubbed'
7575
del data['body']

uv.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)