You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The snake_case convention is common for Python code, but that makes modeling data structures using another convention more difficult. There are two approaches one could take:
Name the dataclass fields exactly like in the data structure
Annotate each field with the databind Alias() setting
Often these naming conventions can be converted to and from using a simple rule-set however. It would be nice to have a decorator that can be applied to a class that injects the Alias() settings for each field, deriving the alias by some specified rule.
Example
fromdataclassesimportdataclassfromdatabind.coreimportfield_auto_aliasing@dataclass@field_auto_aliasing("camelCase")classMyStruct:
some_field: int# Behaves as if we used Annotated[int, Alias("someField")]
The text was updated successfully, but these errors were encountered:
The
snake_case
convention is common for Python code, but that makes modeling data structures using another convention more difficult. There are two approaches one could take:Alias()
settingOften these naming conventions can be converted to and from using a simple rule-set however. It would be nice to have a decorator that can be applied to a class that injects the
Alias()
settings for each field, deriving the alias by some specified rule.Example
The text was updated successfully, but these errors were encountered: