Skip to content

Commit 798fc31

Browse files
rustyconoverclaude
andcommitted
splits: type the canonical filter renderer instead of taking object
_render_filters_canonical took `object`, so mypy rejected every attribute access on it and the repo's own test_mypy_vgi_clean check failed. Typing the parameter as PushdownFilters (under TYPE_CHECKING, to keep the import cost off the runtime path) fixes both accesses. The bound values are pyarrow Scalars, which support int() at runtime but not to the type checker, so _bound_as_int unwraps through as_py first — which is also clearer about what is happening than relying on Scalar.__int__. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 2ad2ad2 commit 798fc31

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

0 Bytes
Binary file not shown.

‎vgi/_test_fixtures/table/splits.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import struct
3030
from dataclasses import dataclass
31-
from typing import Annotated, Any, ClassVar, cast
31+
from typing import TYPE_CHECKING, Annotated, Any, ClassVar, cast
3232

3333
import pyarrow as pa
3434
from vgi_rpc.rpc import OutputCollector
@@ -40,6 +40,9 @@
4040
from vgi.cache_control import CacheControl
4141
from vgi.protocol import PlanResponse, ScanSplit
4242
from vgi.schema_utils import partition_field, schema
43+
44+
if TYPE_CHECKING:
45+
from vgi.table_filter_pushdown import PushdownFilters
4346
from vgi.table_function import (
4447
BindParams,
4548
TableCardinality,
@@ -1079,7 +1082,18 @@ def process(
10791082
return
10801083

10811084

1082-
def _render_filters_canonical(filters: object) -> str:
1085+
def _bound_as_int(value: object) -> int:
1086+
"""Coerce a bound value to a plain int.
1087+
1088+
``ColumnBounds`` carries pyarrow ``Scalar``s, which support ``int()`` at
1089+
runtime but not in the type checker's eyes. Unwrapping through ``as_py``
1090+
first keeps both happy without an ignore comment.
1091+
"""
1092+
as_py = getattr(value, "as_py", None)
1093+
return int(cast(Any, as_py() if callable(as_py) else value))
1094+
1095+
1096+
def _render_filters_canonical(filters: "PushdownFilters | None") -> str:
10831097
"""The CANONICAL cross-SDK rendering of a pushed-down filter set.
10841098
10851099
Every SDK must produce this byte-for-byte, because the shared SQL suite
@@ -1106,10 +1120,10 @@ def _render_filters_canonical(filters: object) -> str:
11061120
# carries no inclusive flag at all, so `n > 40` must render as `n>=41`
11071121
# here or the two workers disagree on a byte.
11081122
if bounds.min_value is not None:
1109-
lo = int(bounds.min_value) + (0 if bounds.min_inclusive else 1)
1123+
lo = _bound_as_int(bounds.min_value) + (0 if bounds.min_inclusive else 1)
11101124
parts.append(f"{c}>={lo}")
11111125
if bounds.max_value is not None:
1112-
hi = int(bounds.max_value) - (0 if bounds.max_inclusive else 1)
1126+
hi = _bound_as_int(bounds.max_value) - (0 if bounds.max_inclusive else 1)
11131127
parts.append(f"{c}<={hi}")
11141128
return ",".join(parts) if parts else "(none)"
11151129

0 commit comments

Comments
 (0)