← Back to issue list

feat: add create_grammar_model()

View original Github issue

Metadata

Project
craft-grammar
Number
#21
Type
pull request
State
merged
Author
tigarmo
Labels
Created
Updated
Closed

Current evaluation

Merged create_grammar_model(), generating grammar-aware classes from Pydantic models by converting standard types. Approved by two reviewers, passes CI, and adds 245 lines across four files.

Suggested action:

No scores available.

Issue body

(this builds on top of #20, only the last commit is new) This function creates the Python code for a grammar-aware class that is compatible with the provided parameter (a Pydantic model class). "Compatible" in this case means that the grammar-aware class has the same (annotated) fields as the original class, but with grammar-aware types. For instance, if the source class has a field called "x" whose type is "str", the grammar-aware class will have a field called "x" whose type is "Grammar[str]". We implement support for many common types but this support is not exhaustive yet.

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Merged create_grammar_model(), generating grammar-aware classes from Pydantic models by converting standard types. Approved by two reviewers, passes CI, and adds 245 lines across four files.
qwen3.6-35b-a3b-mtp-q6 Merged. Introduces create_grammar_model() to generate grammar-aware Python classes from Pydantic models by mapping field types to grammar-aware equivalents like Grammar[str]. Builds on PR #20.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#4 models: create grammar-aware pydantic models (CRAFT-856) craft-grammar merged Merged. Introduces grammar-aware Pydantic models (GrammarStr, GrammarStrList, GrammarSingleEntryDictList) for lifecycle part build-environment attributes. Approved by one reviewer, passed CI, and modified 10 files.
80%
#34 fix(models): make grammar models work with Annotated craft-grammar merged Merged a fix enabling grammar models to support Python's Annotated type hints. Approved by two reviewers, passed CI, and updated two files (+66/-14).
74%
#776 feat: add pydantic models for all sources craft-parts merged Merged to add Pydantic models for all sources, enabling JSON schema generation for parts. Approved by two reviewers, depends on #775, and updates 16 files with a net reduction of 103 lines.
73%