Skip to content

Commit 15aea03

Browse files
rustyconoverclaude
andcommitted
typing: clear all 64 mypy errors in vgi/
Pure type-annotation cleanup — every change is a runtime no-op or behavior-equivalent: - Parameterize pyarrow generics (pa.Field/Scalar/Array, tuple) with [Any] to satisfy disallow_any_generics. - Add a VgiOutputCollector Protocol describing the batch_index= / partition_values= kwargs that VGI's emit-path wrappers add to OutputCollector.emit. Function bodies that opt into those features cast() the framework-supplied out to it; the base OutputCollector type can't carry the wider signature without breaking process() override compatibility across every fixture. - _FilteringOutputCollector: type _inner as _TrackingOutputCollector and add explicit finish/client_log delegators; _TrackingOutputCollector gets explicit finished/output_schema properties (same result as the prior __getattr__ path). - None-guards in simple_writable, bool() wrap in cpp_request_builders, corrected type: ignore codes in worker / azure_sql / catalog_interface. - Also fixes 2 pre-existing ruff F402 errors (loop var shadowing the dataclasses.field import) in protocol.py. mypy vgi/ is now clean; resolves tests/test_mypy_consolidated.py. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5b97619 commit 15aea03

16 files changed

Lines changed: 121 additions & 69 deletions

‎vgi/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from vgi.protocol import (
5555
BindRequest,
5656
InitRequest,
57+
VgiOutputCollector,
5758
)
5859
from vgi.scalar_function import (
5960
RowCountMismatchError,
@@ -128,6 +129,7 @@
128129
"CatalogFunctionType",
129130
"InitRequest",
130131
"Level",
132+
"VgiOutputCollector",
131133
"Message",
132134
"OrderPreservation",
133135
"ParameterInfo",

‎vgi/_test_fixtures/aggregate/streaming.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def streaming_chunk(
138138
partition_key_count: int,
139139
order_key_count: int,
140140
params: ProcessParams[None],
141-
) -> pa.Array:
141+
) -> pa.Array[Any]:
142142
# Column layout from the operator:
143143
# [partition_key_cols..., order_key_cols..., value_cols...]
144144
# We don't actually need the order keys at runtime here — the

‎vgi/_test_fixtures/aggregate/window.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def window_batch(
348348
partition: WindowPartition,
349349
window_state: Any,
350350
params: ProcessParams[None],
351-
) -> pa.Array:
351+
) -> pa.Array[Any]:
352352
out = [cls._sum_one(frames, partition) for frames in subframes]
353353
return pa.array(out, type=pa.int64())
354354

‎vgi/_test_fixtures/simple_writable.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ def _get_user_schema(qualified: str) -> pa.Schema:
194194

195195
def _qualified_from_bind(params: BindParams[None]) -> str:
196196
args = params.bind_call.arguments
197-
if not args.positional:
197+
if not args.positional or args.positional[0] is None:
198198
raise ValueError("table_name positional argument is required")
199199
return str(args.positional[0].as_py())
200200

201201

202202
def _qualified_from_process(params: ProcessParams[None]) -> str:
203203
assert params.init_call is not None
204204
args = params.init_call.bind_call.arguments
205-
if not args.positional:
205+
if not args.positional or args.positional[0] is None:
206206
raise ValueError("table_name positional argument is required")
207207
return str(args.positional[0].as_py())
208208

@@ -290,6 +290,7 @@ def initial_state(cls, params: ProcessParams[None]) -> _ScanState:
290290

291291
@classmethod
292292
def process(cls, params: ProcessParams[None], state: _ScanState, out: OutputCollector) -> None:
293+
assert state.rows is not None and state.schema is not None
293294
if state.cursor >= len(state.rows):
294295
out.finish()
295296
return
@@ -307,7 +308,7 @@ def process(cls, params: ProcessParams[None], state: _ScanState, out: OutputColl
307308

308309
@dataclass(kw_only=True)
309310
class _ScanState(ArrowSerializableDataclass):
310-
rows: Annotated[list[tuple] | None, Transient()] = None
311+
rows: Annotated[list[tuple[Any, ...]] | None, Transient()] = None
311312
schema: Annotated[pa.Schema | None, Transient()] = None
312313
cursor: int = 0
313314

@@ -347,7 +348,7 @@ def process(
347348
col_names = [f.name for f in user_schema]
348349
cols_sql = ", ".join(f'"{c}"' for c in col_names)
349350
placeholders = ", ".join("?" for _ in col_names)
350-
rows_to_insert: list[tuple] = []
351+
rows_to_insert: list[tuple[Any, ...]] = []
351352
for i in range(batch.num_rows):
352353
rows_to_insert.append(tuple(batch.column(c)[i].as_py() for c in col_names))
353354

@@ -402,7 +403,7 @@ def process(
402403
select_list = ", ".join(f'"{c}"' for c in user_col_names)
403404

404405
rowid_col = batch.column("rowid")
405-
updated: list[tuple] = []
406+
updated: list[tuple[Any, ...]] = []
406407
with _connect(attach_opaque_data) as conn:
407408
conn.execute("BEGIN")
408409
for i in range(batch.num_rows):
@@ -454,7 +455,7 @@ def process(
454455
select_list = ", ".join(f'"{c}"' for c in user_col_names)
455456
rowid_col = batch.column("rowid")
456457

457-
deleted: list[tuple] = []
458+
deleted: list[tuple[Any, ...]] = []
458459
with _connect(attach_opaque_data) as conn:
459460
conn.execute("BEGIN")
460461
for i in range(batch.num_rows):
@@ -509,7 +510,7 @@ def process(
509510
col_names = [f.name for f in user_schema]
510511
cols_sql = ", ".join(f'"{c}"' for c in col_names)
511512
placeholders = ", ".join("?" for _ in col_names)
512-
rows_to_insert: list[tuple] = []
513+
rows_to_insert: list[tuple[Any, ...]] = []
513514
for i in range(batch.num_rows):
514515
rows_to_insert.append(tuple(batch.column(c)[i].as_py() for c in col_names))
515516

‎vgi/_test_fixtures/table/batch_index.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import struct
3333
from dataclasses import dataclass
34-
from typing import Annotated, ClassVar
34+
from typing import Annotated, ClassVar, cast
3535

3636
import pyarrow as pa
3737
from vgi_rpc import ArrowSerializableDataclass
@@ -41,6 +41,7 @@
4141
from vgi.arguments import Arg
4242
from vgi.invocation import GlobalInitResponse
4343
from vgi.metadata import FunctionExample, OrderPreservation
44+
from vgi.protocol import VgiOutputCollector
4445
from vgi.schema_utils import schema
4546
from vgi.table_function import (
4647
InitParams,
@@ -155,7 +156,7 @@ def process(
155156

156157
batch_end_idx = min(state.current_idx + cls.BATCH_SIZE, state.current_end or 0)
157158
values = list(range(state.current_idx, batch_end_idx))
158-
out.emit(
159+
cast(VgiOutputCollector, out).emit(
159160
pa.RecordBatch.from_pydict({"n": values}, schema=params.output_schema),
160161
batch_index=state.partition_id,
161162
)
@@ -261,7 +262,7 @@ def process(
261262
rows = batch_end_idx - state.current_idx
262263
partition_ids = [state.partition_id] * rows
263264
seqs = list(range(state.current_idx - (state.current_start or 0), batch_end_idx - (state.current_start or 0)))
264-
out.emit(
265+
cast(VgiOutputCollector, out).emit(
265266
pa.RecordBatch.from_pydict(
266267
{"partition_id": partition_ids, "seq": seqs},
267268
schema=params.output_schema,

‎vgi/_test_fixtures/table/batch_index_broken.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from __future__ import annotations
3333

3434
from dataclasses import dataclass
35-
from typing import Annotated, ClassVar
35+
from typing import Annotated, ClassVar, cast
3636

3737
import pyarrow as pa
3838
from vgi_rpc import ArrowSerializableDataclass
@@ -41,6 +41,7 @@
4141
from vgi._test_fixtures.table._common import _cardinality_from_count
4242
from vgi.arguments import Arg
4343
from vgi.metadata import OrderPreservation
44+
from vgi.protocol import VgiOutputCollector
4445
from vgi.schema_utils import schema
4546
from vgi.table_function import (
4647
ProcessParams,
@@ -145,14 +146,14 @@ def process(
145146
{"n": [42]},
146147
schema=params.output_schema,
147148
)
148-
out.emit(batch, batch_index=3)
149+
cast(VgiOutputCollector, out).emit(batch, batch_index=3)
149150
out.finish()
150151
return
151152
batch = pa.RecordBatch.from_pydict(
152153
{"n": list(range(params.args.count))},
153154
schema=params.output_schema,
154155
)
155-
out.emit(batch, batch_index=10)
156+
cast(VgiOutputCollector, out).emit(batch, batch_index=10)
156157
state.emitted = True
157158

158159

@@ -193,5 +194,5 @@ def process(
193194
schema=params.output_schema,
194195
)
195196
# 2^60 — far above the 10^13 cap.
196-
out.emit(batch, batch_index=1 << 60)
197+
cast(VgiOutputCollector, out).emit(batch, batch_index=1 << 60)
197198
state.emitted = True

‎vgi/_test_fixtures/table/partition_columns.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import struct
4444
from dataclasses import dataclass
45-
from typing import Annotated, ClassVar
45+
from typing import Annotated, ClassVar, cast
4646

4747
import pyarrow as pa
4848
from vgi_rpc import ArrowSerializableDataclass
@@ -52,6 +52,7 @@
5252
from vgi.arguments import Arg
5353
from vgi.invocation import GlobalInitResponse
5454
from vgi.metadata import FunctionExample, PartitionKind
55+
from vgi.protocol import VgiOutputCollector
5556
from vgi.schema_utils import partition_field
5657
from vgi.table_function import (
5758
InitParams,
@@ -364,7 +365,7 @@ def process(
364365
{"category": [category] * rpc, "revenue": revenue},
365366
schema=cls.FIXED_SCHEMA,
366367
)
367-
out.emit(
368+
cast(VgiOutputCollector, out).emit(
368369
batch,
369370
partition_values={
370371
"category": (

‎vgi/_test_fixtures/table/partition_columns_broken.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from __future__ import annotations
3939

4040
from dataclasses import dataclass
41-
from typing import Annotated, ClassVar
41+
from typing import Annotated, Any, ClassVar, cast
4242

4343
import pyarrow as pa
4444
from vgi_rpc import ArrowSerializableDataclass
@@ -47,6 +47,7 @@
4747
from vgi._test_fixtures.table._common import _cardinality_from_count
4848
from vgi.arguments import Arg
4949
from vgi.metadata import PartitionKind
50+
from vgi.protocol import VgiOutputCollector
5051
from vgi.schema_utils import partition_field
5152
from vgi.table_function import (
5253
ProcessParams,
@@ -174,7 +175,7 @@ def process(
174175
{"country": ["US"] * params.args.count, "sales": list(range(params.args.count))},
175176
schema=cls.FIXED_SCHEMA,
176177
)
177-
out.emit(
178+
cast(VgiOutputCollector, out).emit(
178179
batch,
179180
partition_values={
180181
"country": (
@@ -197,11 +198,13 @@ class BrokenPartitionValuesNoAnnotationFunction(TableFunctionGenerator[_BrokenAr
197198
"""No partition annotation, but worker passes partition_values=."""
198199

199200
# No partition_field() — bind schema has no partition columns.
201+
# cast: mypy joins Field[StringType] + Field[Int64Type] to Field[object];
202+
# the runtime list is a plain list of pa.Field.
200203
FIXED_SCHEMA: ClassVar[pa.Schema] = pa.schema(
201-
[
202-
pa.field("country", pa.string()),
203-
pa.field("sales", pa.int64()),
204-
]
204+
cast(
205+
"list[pa.Field[Any]]",
206+
[pa.field("country", pa.string()), pa.field("sales", pa.int64())],
207+
)
205208
)
206209

207210
class Meta:
@@ -233,7 +236,7 @@ def process(
233236
{"country": ["US"] * params.args.count, "sales": list(range(params.args.count))},
234237
schema=cls.FIXED_SCHEMA,
235238
)
236-
out.emit(
239+
cast(VgiOutputCollector, out).emit(
237240
batch,
238241
partition_values={
239242
"country": (

‎vgi/aggregate_function.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def window_batch(
484484
partition: WindowPartition,
485485
window_state: Any,
486486
params: ProcessParams[Any],
487-
) -> pa.Array | list[Any]:
487+
) -> pa.Array[Any] | list[Any]:
488488
"""Compute the aggregate value for ``count`` consecutive output rows.
489489
490490
Default implementation calls :meth:`window` once per row. Override
@@ -559,7 +559,7 @@ def streaming_chunk(
559559
partition_key_count: int,
560560
order_key_count: int,
561561
params: ProcessParams[Any],
562-
) -> pa.Array | list[Any]:
562+
) -> pa.Array[Any] | list[Any]:
563563
"""Process one chunk of streaming input.
564564
565565
Args:

‎vgi/catalog/catalog_interface.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ def _inline_bind_result_for(func_cls: type) -> bytes | None:
16031603
return cached # type: ignore[no-any-return]
16041604
from vgi.invocation import BindResponse
16051605

1606-
response = BindResponse(output_schema=func_cls.FIXED_SCHEMA, opaque_data=None)
1606+
response = BindResponse(output_schema=func_cls.FIXED_SCHEMA, opaque_data=None) # type: ignore[attr-defined]
16071607
blob = response.serialize_to_bytes()
16081608
# Set on the class itself so subclasses don't pollute their parents'
16091609
# cache with each other's serialized blobs (FIXED_SCHEMA may differ).

0 commit comments

Comments
 (0)