python-attrs / cattrs

Composable custom class converters for attrs, dataclasses and friends.
https://catt.rs
MIT License
818 stars 113 forks source link

cattrs does not consider 'alias' argument for field function in attrs. #362

Closed ranjithvuppala closed 1 year ago

ranjithvuppala commented 1 year ago

Description

when using structure_attrs_fromdict cattrs doesnot honour 'alias' name for the field..

For example:

@define
class Dummy:
    key1: str
    key3: str = field(alias="key2")

input_dict = {"key1": "test1", "key2": "test3"}
cattrs.structure_attrs_fromdict(b, Dummy)

Should work. But it gives this error

TypeError: Dummy.__init__() missing 1 required positional argument: 'key2'

Where as creating attrs class direclty works instance = Dummy(key1 = "value1", key2="value2")

Tinche commented 1 year ago

Hello,

closing as dupe of #322. Haven't gotten around to it yet!

ranjithvuppala commented 1 year ago

closed in favour of #322