-
Notifications
You must be signed in to change notification settings - Fork 22
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: allow no key transformations #94
Conversation
dataclass_wizard/enums.py
Outdated
@@ -27,6 +27,9 @@ class LetterCase(Enum): | |||
# Converts strings (generally in camel case) to snake case. | |||
# ex: `myFieldName` -> `my_field_name` | |||
SNAKE = FuncWrapper(to_snake_case) | |||
# Perfoms no conversion on strings. | |||
# ex: `MY_FIELD_NAME` -> `MY_FIELD_NAME` | |||
NONE = FuncWrapper(str) |
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.
hmm... just wondering... wouldn't lambda o: o
be slightly more optimal here? assuming that we are loading from JSON, where all keys are a str
anyway.
I don't have any problem with str()
but it seems to just do unnecessary conversion when in 99% of cases, one could expect a key to be a str
anyway. Let me know your thoughts @cquick01 .
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.
That sounds reasonable, I'll push that change shortly. Thanks!
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.
Tested briefly with the example script in the PR, all seems to be working 👍
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.
LGTM @cquick01 . I kicked off the CI workflow, will take a look and merge / deploy version later today if all seems good.
Closes #92 - just linking issue directly here. |
@rnag Did this change get reversed? I see that NONE is not allowed :( and this code isn't in main? https://github.com/cquick01/dataclass-wizard/blob/main/dataclass_wizard/enums.py |
@adamcunnington-mlg I see it in main - https://github.com/rnag/dataclass-wizard/blob/main/dataclass_wizard/enums.py#L32 But I don't think a new tag/release was done |
@rnag please can you make a release? |
Bump @rnag - would like this feature. Thanks! |
Sorry for the delay -- I just released v0.23.0 with the update to allow no key transformations. Thanks for your work on this @cquick01 -- I credited you in the release notes. |
@rnag thank you for this! Please can you also review, PR, https://github.com/rnag/dataclass-wizard/pull/125/files which address 1 other open bug issue |
Allows the ability to define keys in JSON/dataclass that do not undergo transformation.
prints with no transformations