-
-
Notifications
You must be signed in to change notification settings - Fork 133
Closed
Milestone
Description
- cattrs version: 0.9.0
- Python version: 3.7.0
- Operating System: Windows
Description
Right now cattr can only convert dictionaries back to the respective attr object if the field can be initialized in __init__ (because it calls cl(**conv_obj)). Is it possible for cattr to work with fields with init set to False?
What I Did
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import attr
>>> import cattr
>>> @attr.s
... class A:
... a: int = attr.ib(init=False)
...
>>> a = A()
>>> a.a = 10
>>> s = cattr.unstructure(a)
>>> cattr.structure(s, A)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\.virtualenvs\test\lib\site-packages\cattr\converters.py", line 178, in structure
return self._structure_func.dispatch(cl)(obj, cl)
File "D:\.virtualenvs\test\lib\site-packages\cattr\converters.py", line 298, in structure_attrs_fromdict
return cl(**conv_obj)
TypeError: __init__() got an unexpected keyword argument 'a'
>>>
Reactions are currently unavailable