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
I just discover that setting a value using attribute setter is different, in a very counter intuitive way, than setting a value using item setter.
Let's start again with #42 example. When given a regular dict, Prodict does not perform a deep transformation in order to convert nested dict into nested Prodict:
When starting with an empty dict and setting a, the result differ if we use an item setter or an attribute setter. Still not really consistent:
>>>d=Prodict()
>>>d['a']=a# <-- No conversion>>> type(d.a)
<class'dict'>>>>d.aisaTrue>>>d=Prodict()
>>>d.a=a# <-- Deep copy and conversion>>> type(d.a)
<class'prodict.Prodict'>>>>type(d.a.foo)
<class'prodict.Prodict'>>>>d=Prodict()
>>>d.update(a=a) # <-- No conversion>>> type(d.a)
<class'dict'>>>>type(d.a)
>>>d.aisaTrue
And when value is already a Prodict a deep copy is made even if it seems unnecessary:
>>>a=Prodict(x=100,y=200,foo={'z':300})
>>>a
{'x': 100, 'y': 200, 'foo': {'z': 300}}
>>> type(a.foo)
<class'prodict.Prodict'>>>>d=Prodict()
>>>d.a=a>>>d.aisa# <-- expected to be True, why perform a deep copy?False>>>d.a.fooisa.fooFalse
So, what would be a clean semantic?
At least, attribute setter (d.a=...), item setter (d['a']=...), update (d.update(a=...)) and kwargs initialization (Prodict(a=...) or Prodict((('a',...),))) should behave the very same way
Whether a deep copy is made or not (design choice, I'd go for a deep conversion), it should be documented
Instances of Prodict should not be copied (and possibly not inspected more deeply if a deep conversion is performed)
Best regards
The text was updated successfully, but these errors were encountered:
Hi,
I just discover that setting a value using attribute setter is different, in a very counter intuitive way, than setting a value using item setter.
Let's start again with #42 example. When given a regular
dict
,Prodict
does not perform a deep transformation in order to convert nesteddict
into nestedProdict
:On the other hand, when intialized with a keyword arg, a deep conversion is done... which is not consistent with previous exemple:
When starting with an empty dict and setting
a
, the result differ if we use an item setter or an attribute setter. Still not really consistent:And when value is already a
Prodict
a deep copy is made even if it seems unnecessary:So, what would be a clean semantic?
d.a=...
), item setter (d['a']=...
), update (d.update(a=...)
) and kwargs initialization (Prodict(a=...)
orProdict((('a',...),))
) should behave the very same wayBest regards
The text was updated successfully, but these errors were encountered: