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
When I am trying use structure on an attr class having default values set for few optional attributes, those default values are being ignored and not returning to returned object
What I Did
Here is the sample code:
import attr
from cattr import structure, typed
from typing import Optional
@attr.s
class A(object):
a = typed(Optional[int], default=0)
@attr.s
class B(object):
b = attr.ib(validator=optional(instance_of(int)), default=0)
When I tried structure({}, A) I expected A1(a=0) but I get A1(a=None)
Similarly for structure({}, B) I get following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/xxx/cattr/converters.py", line 171, in structure
return self.structure_func.dispatch(cl)(obj, cl)
File "/xxx/cattr/converters.py", line 86, in <lambda>
lambda *args, **kwargs: self.structure_attrs(*args, **kwargs))
File "/xxx/cattr/converters.py", line 276, in structure_attrs_fromdict
converted = self._structure_attr_from_dict(a, name, obj)
File "/xxx/cattr/converters.py", line 286, in _structure_attr_from_dict
return mapping[name]
KeyError: 'b'
Hi! This is a duplicate of #10 I think. It's something I will look at after attrs 17.3 is released and I do another development pass of cattrs. Thanks for your interest :)
Description
When I am trying use structure on an attr class having default values set for few optional attributes, those default values are being ignored and not returning to returned object
What I Did
Here is the sample code:
When I tried
structure({}, A)
I expectedA1(a=0)
but I getA1(a=None)
Similarly for
structure({}, B)
I get following errorA fix something like will fix the issue: shwetas1205@7d6d6fa
The text was updated successfully, but these errors were encountered: