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

Add an alternative way to assign a field alias with annotations #214

Closed
Fatal1ty opened this issue Apr 19, 2024 · 0 comments · Fixed by #215
Closed

Add an alternative way to assign a field alias with annotations #214

Fatal1ty opened this issue Apr 19, 2024 · 0 comments · Fixed by #215
Labels
enhancement New feature or request

Comments

@Fatal1ty
Copy link
Owner

Is your feature request related to a problem? Please describe.
The current way to assign an alias to a field is to use field metadata:

@dataclass
class Foo:
    a: str = field(metadata={"alias": "alias_a"})
    b: str = field(metadata=field_options(alias="alias_b"))

This can be written in alternative shorter way.

Describe the solution you'd like
Add a new Alias class and use it as an annotation:

@dataclass
class Foo:
    a: Annotated[str, Alias("alias_a")]
    b: Annotated[str, Alias("alias_b")]

Describe alternatives you've considered
An alternative can be a la Meta class with an alias attribute. Nothing prevents us from adding such a class in the future and duplicating the functionality in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant