-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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
from dataclasses import dataclass
from databind.core import field_auto_aliasing
@dataclass
@field_auto_aliasing("camelCase")
class MyStruct:
some_field: int # Behaves as if we used Annotated[int, Alias("someField")]