feat(typespec): parameterized backend_type fidelity + raise on invalid (item 54, gap 1) - #294
Merged
discreteds merged 6 commits intoAug 17, 2026
Merged
Conversation
…type (item 54, task 6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Item 54, PR-1 (gap 1 + validation strictness): the canonical resolver
_resolve_field_nativesilently dropped parameterizedbackend_typestrings on Polars/Narwhals/PyArrow (Ibis/Pandas were already correct), and silently absorbed invalidbackend_typestrings into a canonical fallback.This PR:
core/dtypes/_paramstring.py— a restricted AST-validated parser for constructor-call-style dtype reprs (Polars/Narwhalsstr(dtype)output), shared by both targets. Closed whitelist namespace; adversarial-tested (no eval of unvalidated input).parse_type_stringon Polars and Narwhals (safe-eval parser) and PyArrow (bounded bracket/paren regex family: timestamp/duration/time/decimal) — parameterized dtypes likeDatetime(time_unit='us', time_zone='UTC'),Decimal(precision=38, scale=10),List(Int64),Array(Int64, shape=(5,))now round-trip to real native dtypes instead of canonical fallback.InvalidBackendTypeErrorand wires it into_resolve_field_native: a non-empty, non-Nonebackend_typethe target cannot parse now raises (names field + string + target) instead of silently degrading.None/""fall through unchanged (item 53's ANY→STRING path preserved).TestInlineReadItem54Deferred→TestInlineReadParameterizedBackendType(the deliberate flip item 53 left for item 54).Spec:
2026-08-16-converters-resolver-dtype-fidelity-design.md(rev 2, GLM-5.2 adversarial review folded). Plan tasks 1–6, RED-first TDD, one commit per task.Verification
hatch run ruff:check: cleanhatch run mypy:check: 0 new errors (98 pre-existing, allimport-untyped/fixture-class errors present at baseline; touched files contribute only pre-existing pyarrowimport-untyped)FieldSpec(backend_type=...)string literal exists; only test usages (all parseable or intentional raise cases)