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
rename reserved keywords #33
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice change, using the keyword library could simplify this.
Maybe for backward compatibility we should add the original name as a alias in the pydantic model. This way converting from avsc to pydantic and back to avsc stays the same keys.
I would say we should make a new issue for this and a new PR
@@ -1,6 +1,41 @@ | |||
import json | |||
from typing import Optional, Union | |||
|
|||
RESERVED_KEYWORDS= { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this list be replaced by the keyword package?
See also:
https://docs.python.org/3/library/keyword.html
@@ -83,6 +119,7 @@ def record_type_to_pydantic(schema: dict): | |||
|
|||
for field in schema["fields"]: | |||
n = field["name"] | |||
n = n if n not in RESERVED_KEYWORDS else f"{n}_" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be replaced by this:
if keyword.iskeyword(n)
n = f"{n}_"
Can you also add some testing for this? |
Codecov Report
@@ Coverage Diff @@
## main #33 +/- ##
==========================================
+ Coverage 89.08% 89.26% +0.18%
==========================================
Files 2 2
Lines 174 177 +3
==========================================
+ Hits 155 158 +3
Misses 19 19
Continue to review full report at Codecov.
|
WIP for #32