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

rename reserved keywords #33

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

Conversation

jonykalavera
Copy link

@jonykalavera jonykalavera commented Apr 8, 2022

WIP for #32

Copy link
Collaborator

@ffinfo ffinfo left a 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= {
Copy link
Collaborator

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}_"
Copy link
Collaborator

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}_"

@ffinfo
Copy link
Collaborator

ffinfo commented Apr 21, 2022

Can you also add some testing for this?

@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2022

Codecov Report

Merging #33 (12a31d7) into main (5388e41) will increase coverage by 0.18%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
src/pydantic_avro/avro_to_pydantic.py 83.15% <100.00%> (+0.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5388e41...12a31d7. Read the comment docs.

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.

None yet

3 participants