Skip to content

Invalid name generation when using python reserved keywords #89

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

QuentinN42
Copy link

Fixes #88

To fix this issue, here is my proposition:

 class Author(pydantic.BaseModel):
+     model_config = pydantic.ConfigDict(
+        validate_by_alias=True,
+        validate_by_name=True,
+    )
     id: int
+    class_: str = pydantic.Field(
+        alias="class",
+    )
-    class: str
  1. I'm replacing the class reserved keyword by class_.
  2. I add validate_by_name to allow us to define the class using Author(class_=...).
  3. I add validate_by_alias to allow JSON serde.

Changes overview

  1. I've created a new file : internal/poet/reserved.go to append _ to reserved names.
  2. I've modified internal/gen.go::pydanticNode to add model_config = pydantic.ConfigDict
  3. I've modified internal/gen.go::fieldNode:
  • If not reserved keyword, code unchanged.
  • Else if using pydantic, add the _ and add pydantic.Field(...)
  • Else if dataclasses, only add the _
  1. Added tests

Questions / possible issues

  1. To run the tests, I just clonned the repo and ran make test is it correct ?
  2. I had to update all comment from sqlc v1.28.0 to sqlc v1.29.0 is this intended ?
  3. The wasm sha256 changed, should I commit that ?
  4. In internal/poet/reserved.go I hardcoded reservedKeywords we should double check it and check if we want to keep it like that.
  5. Do you want me to add more tests ?

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.

Invalid name generation when using python reserved keywords
1 participant