addict icon indicating copy to clipboard operation
addict copied to clipboard

Deep setattr and gettattr when attribute names contain '.'

Open evanjtravis opened this issue 6 years ago • 2 comments

Would it be possible (prudent?) for the Dict.__setattr__ and Dict.__getattr__ functions to be modified to make nested attribute gets/sets when given attribute names that contain periods?

For example:

>>> from addict import Dict
>>> 
>>> d = Dict()
>>> d.date.year = 2019
>>> setattr(d, "date.month", "FEB")
>>>
>>> d.date.year
2019
>>> getattr(d, "date.month")
'FEB'
>>> getattr(d, "date.year")
{} # Desired output: 2019
>>> d.date.month
{} # Desired output: 'FEB'
>>>

evanjtravis avatar Feb 20 '19 22:02 evanjtravis

Im sure this has been handled already but based on the title, when you use dot notation it will automatically do a deep copy?

MorenoBandito avatar Jan 30 '20 14:01 MorenoBandito

definitely possible, slightly worried about breaking something.

mewwts avatar Sep 12 '20 07:09 mewwts