Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add create_grammar_model() #21

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Conversation

tigarmo
Copy link
Collaborator

@tigarmo tigarmo commented Apr 18, 2024

(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.

@tigarmo tigarmo force-pushed the CRAFT-2703-create-grammar-model branch 11 times, most recently from 07f6c17 to 6c44641 Compare April 18, 2024 19:55
@tigarmo tigarmo marked this pull request as ready for review April 18, 2024 19:56
@tigarmo tigarmo requested review from cmatsuoka and lengau April 18, 2024 19:56
@tigarmo tigarmo force-pushed the CRAFT-2703-create-grammar-model branch from 6c44641 to 9c36b63 Compare April 19, 2024 11:30
craft_grammar/create.py Show resolved Hide resolved
Copy link
Contributor

@cmatsuoka cmatsuoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, this should allow us to declare Grammar[Part] and have everything properly handled.

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.
@tigarmo tigarmo force-pushed the CRAFT-2703-create-grammar-model branch from 9c36b63 to ba33b6b Compare April 19, 2024 19:21
@tigarmo tigarmo merged commit 755aa9b into main Apr 19, 2024
6 checks passed
@tigarmo tigarmo deleted the CRAFT-2703-create-grammar-model branch April 19, 2024 19:23
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.

3 participants