Skip to content

fix(schema): fix pre-existing pyright errors in BaseValueSchema and constrained builders#83

Open
xujustinj wants to merge 3 commits intomainfrom
fix/pyright-schema-errors
Open

fix(schema): fix pre-existing pyright errors in BaseValueSchema and constrained builders#83
xujustinj wants to merge 3 commits intomainfrom
fix/pyright-schema-errors

Conversation

@xujustinj
Copy link
Contributor

Summary

Fixes 22 pre-existing pyright errors introduced in #76 (feat(values): constrained Value subclasses, x-value-type field, and $defs safety).

Two root causes:

  • BaseValueSchema.value_type alias: The field used validation_alias="x-value-type" + serialization_alias="x-value-type", but pyright's Pydantic plugin can't handle non-identifier aliases and misreported value_type as a required parameter. Fixed by making it a plain field and doing the x-value-typevalue_type translation manually in the already-existing model_validator and model_serializer.

  • TypeVar in function body: _build_constrained_sequence_cls and _build_constrained_map_cls created a TypeVar inside the function body and used it as a generic parameter in type() calls. Pyright doesn't support TypeVars defined in function scope as generic parameters. Fixed by moving _T_item to module scope and adding # type: ignore on the dynamic type() lines (which pyright can't statically analyze by design).

Also updates two tests that passed x-value-type via **{...} kwargs (invalid Python identifier) to use model_validate() instead.

Test plan

  • uv run pyright reports 0 errors
  • uv run pytest — 413 passed, 1 xfailed
  • uv run ruff check . — no issues

🤖 Generated with Claude Code

xujustinj and others added 3 commits February 28, 2026 03:14
…try builders

Adds removal support to NodeRegistryBuilder and ValueRegistryBuilder with
a missing_ok parameter (default false). In lazy builders, removals are
stored separately and applied after all additions at build time, so a
removal always wins regardless of call order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lue builders

Two pre-existing issues introduced in #76:

1. BaseValueSchema.value_type used validation_alias/serialization_alias with
   "x-value-type", which pyright's Pydantic plugin can't handle (non-identifier
   alias). Replaced with a plain field and manual x-value-type <-> value_type
   translation in the existing model_validator and model_serializer.

2. _build_constrained_sequence_cls and _build_constrained_map_cls created
   TypeVars inside function bodies and used them as generic parameters in
   type() calls. Moved TypeVar to module scope and added type: ignore comments
   on the dynamic type() lines that pyright cannot statically analyze.

Also updates two tests that constructed IntegerValueSchema via
**{"x-value-type": ...} kwargs (not valid Python identifiers) to use
model_validate() instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant