Repository navigation
feat: let a component list its template_data() keys for citry check - #423
Merged
Merged
Conversation
Citry reads template_data() to learn which names a template can use. When the method builds its result through a helper, Citry cannot tell a typo from a name the helper adds, so citry check could only say that a name might be supplied dynamically. About 60 Citry UI templates were in that state, which is why citry check --include-libraries reported ~1,500 such errors on an app that registers Citry UI. A component can now list the keys in Lint.template_data_keys. Only citry check and the editor read it. The template may then use the listed keys, the keys Citry can read from the method, and the declared variables, so a typo is reported as a name the template cannot use, and the editor offers the listed keys as completions. citry check warns about a key the method writes as a literal that the list leaves out (citry.template.undeclared-template-data-key). The source analysis also keeps the literal keys set on a helper's result, as in data = build(kwargs); data["x"] = ..., while still treating the result as possibly holding more keys. Error modes, all when the class is defined: a value that is not a tuple, list or frozenset of strings raises TypeError; a name that cannot be a Python variable name, such as "class", or a name listed twice raises ValueError; a class that declares both the list and a TemplateData schema raises TypeError. A schema on a subclass replaces an inherited list, so a subclass of a Citry UI component can still add one, and template_data_keys = None clears an inherited list. The 60 Citry UI components now declare their keys, taken from the keys their template_data() returned across the whole Citry UI test suite. Every name their templates use was among them, so no template bug turned up. A new Citry UI test checks those templates with --include-libraries and keeps the lists complete. Fixes #149 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 27, 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.
Fixes #149. This is the second PR for it. The first, #402, made
citry checkleave out findings in registered libraries. This one adds the option the maintainer approved, so thatcitry check --include-librariescan check Citry UI's own templates.What changes
Citry reads
template_data()to learn which names a template can use. When the method builds its result through a helper, Citry can't tell a typo from a name the helper adds. It then reports every name in the template as "not declared. Citry could not determine whether it is supplied dynamically". About 60 Citry UI templates were in that state, and they produced about 1,500 errors with--include-libraries.A component can now list its keys:
citry checkand the editor read the list; rendering ignores it.dict. The editor's completion offers the listed keys.{"title": ...}ordata["title"] = ..., and the list leaves out gets a warning incitry check. It's the new codecitry.template.undeclared-template-data-key.data = build(kwargs); data["x"] = .... It still treats that result as possibly holding more keys.TypeError;"class", or a name listed twice, raisesValueError;TemplateDataschema raisesTypeError.template_data_keys = Noneclears an inherited list. ATemplateDataschema on a subclass replaces an inherited list too, so an app's subclass of a Citry UI component can still describe its data with a schema.Citry UI
The 60 Citry UI components with this problem now declare their keys. How I got the lists:
template_data()returned across the whole citry_ui test suite.citry check --include-librarieson an app that registers only Citry UI now reports no unknown-variable errors and no undeclared-key warnings. Two existingcitry.js-data.unsupported-typewarnings remain, for theserverDefaultsof CCascader and CInfiniteScroll; they're out of scope.Each
Lintclass sits after the component's input schemas, as the Citry UI guide asks.Docs and downstream
docs_site/content/ide/template-linting.md: the new "List template data keys" section;Component.Lintdocstring.unknown-variablefix text, which now points to the list;_diagnostic_catalog.py, regenerated.docs/design/template_linting.md: namespace policy, resolution order and error modes;packages/py/citry_ui/docs/component-authoring.md: when to declare the list and how to keep it current.CHANGELOG.mdandpackages/protocol/diagnostics/CHANGELOG.md.TemplateLintInfocarries the list to the language server. The field is left out when it's empty, so a language server from an older citry still reads the record.Tests
packages/py/citry/tests/test_lint_template_data_keys.pycovers:Noneand the schema-on-subclass case;test_template_data_source.py: keys set on a helper's result are kept, and a non-call value still proves nothing.citry_lsp/tests/test_engine.py: the editor reports the typo against the list and offers the listed key as a completion.citry_ui/tests/test_citry_ui_registration.py:test_citry_ui_templates_check_clean_against_their_declared_keysrunsinclude_libraries=Trueand fails when a template reads a name its list leaves out;test_a_subclass_of_a_citry_ui_component_may_describe_its_data_with_a_schema.Known limits
template_datachain. Where it can't, for example a decoratedtemplate_data,citry checkstill reports a typo but the editor shows nothing.data.update(badge=1), has no source position, so the drift warning doesn't cover it.Kwargsallows extra keys that pass through.citry_uideclarescitry>=0.6.0, and citry 0.6.0 rejects an unknownLintsetting. The next citry-ui release needs to raise that floor.check_input_typesalready needed it.Evidence (local)
-m "not e2e") together with the new citry tests andcitry_lsp/tests/test_engine.py: 3,666 passed.PR CI runs the cargo phases and the full matrix.
🤖 Generated with Claude Code