Repository navigation
feat: check component input types at render time - #208
Merged
Merged
Conversation
When a component renders, Citry now checks each Kwargs, TemplateData, JsData, CssData, and render-time State field against its annotation and raises TypeError for a value of the wrong outer type, in every mode. Citry(check_input_types=False) and Component.check_input_types turn the check off. Annotations resolve in the module of the class that declares them; names that cannot be evaluated, Any, TypeVar, and non-runtime Protocols stay unchecked. A field's own default always passes, int accepts bool and registered integers, float accepts real numbers but not Decimal, and str accepts Django lazy text. The check found real type mismatches in the benchmark scenario, the docs search modal, and two tests; those are fixed. The built-in <c-cache> and the Citry UI components keep their own, more specific input errors by turning the general check off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Event calls turn a JSON list back into a tuple for State fields annotated as a tuple, so a handler that renders from its State no longer fails the Kwargs check (and handlers see the declared type). - <c-i18n> and <c-mark> keep their own tag-named input errors, like <c-cache>. - The error message writes None as None, adds the module when two classes share a name, asks for an allowed value for Literal and type[...], and suggests c-<name> when a template attribute passed text. - Django lazy text passes for str only when it wraps a str; a subscripted generic type alias checks the type it stands for. - Docs: reorder the value-type section so the common fixes come first, correct the default and skipped-annotation rules, update the django-components migration guide (DJC-072, new DJC-096), and state in both changelogs that Citry UI must be upgraded together with Citry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
12 tasks
On Python 3.10 a parameterized generic such as `tuple[str, ...]` passes `isinstance(hint, type)`, and isinstance() and issubclass() then reject it. A browser update to a State field annotated that way failed with a 500, and a handler's `list[...]` return annotation could raise while documenting the API. The State update check now accepts a JSON list for a tuple field and tells generics apart by their origin; the OpenAPI data check does the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dialog and Form pass None when the caller chose no color or variant, and get_styling_css() treats None as the default styling, but Button's annotations did not allow None. The input type check rejected the benchmark dialog's render in the e2e suite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks
Replace the app-wide Citry(check_input_types=...) argument with a check_input_types field on LintSettings, and the per-component class attribute with check_input_types in the nested Lint class, which combines across bases like the other Lint settings. ComponentMeta resolves the component's choice once per class while validating Lint, so renders read one stored value. Citry UI components and the built-in mark, cache, and i18n components opt out through their Lint class. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the structural Citry UI test with one that installs the library and renders an input its annotation does not name, document when Lint's check_input_types is read, use one TypeError wording for both settings, and cover TemplateData, State, base-order precedence, per-app library installs, and simple components. Reword the Citry UI opt-out comment and the affected docs and changelog entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks
# Conflicts: # CHANGELOG.md # packages/py/citry/citry/_linting.py # packages/py/citry/citry/settings.py
This was referenced Oct 24, 2026
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.
Closes one of the gaps the error-prevention benchmark found (#207, #158):
Card(title=123)againsttitle: strused to render123with no error.What changes
Citry now checks the outer type of each component input against its annotation on every render, in every mode:
Kwargson every render path,TemplateData/JsData/CssData, andStatebuilt from kwargs orstate_data(). It does not cover State rebuilt from an event token, Pydantic models, dataclasses with their own__init__, or Slots.list, not its items), and skipsAny,object, type variables, plainProtocols and names imported only for type checking.Citry(lint=LintSettings(check_input_types=False))for the whole app, orcheck_input_types = Falsein a component'sclass Lint:.Truein a component'sLintturns it back on when the app turns it off. Citry reads the component's choice once, when the class is defined.Edge cases, each documented:
strare accepted forstr.Decimalis rejected forfloat; annotatefloat | Decimalto accept both.x: str = Nonekeeps working.intacceptsbooland numpy integers.A related fix: event handlers whose State has a tuple field no longer fail with a 500 after JSON turns the tuple into a list.
Cost
The budget was under 1% render regression on the Kwargs-heavy benchmark scenario. Measured against
origin/mainin alternating fresh processes, the median was +0.17% (12 pairs). One check costs about 300 ns; about 29 ns with the check off.Checks
--platform linuxpassed. docs tests: 1,050 passed. The docs build had 0 errors and 0 warnings.🤖 Generated with Claude Code