This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Pritish Patil
Recipients Pritish Patil, docs@python
Date 2017-09-01.14:51:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1504277476.43.0.203831960923.issue31322@psf.upfronthosting.co.za>
In-reply-to
Content
I am new here and not sure how I can suggest this properly.


When using nested SimpleNamespaces, a making a copy by using 

new_NS=SimpleNamespace(**namespace.__dict__.copy())

only copies the highest level namespace. This is expected in python as shallow copies are preferred. But, a nested deep copy function would be nice, and will allow easier use.

I suggest a simple

def my_namespace_copy(namespace):
    '''Recursively deep copies nested namespaces'''
    new_NS=SimpleNamespace(**namespace.__dict__.copy())
    for i in new_NS.__dict__.keys():
        if(type(new_NS.__dict__[i]) == types.SimpleNamespace):
            new_NS.__setattr__(i, my_namespace_copy(new_NS.__getattribute__(i)))
    return new_NS

I am not sure of the exact implementation of the class and guess this would need some appropriate modifications.

I suggest this be added at SimpleNameSpace.__copy__ or at SimpleNameSpace.__deepcopy__
History
Date User Action Args
2017-09-01 14:51:16Pritish Patilsetrecipients: + Pritish Patil, docs@python
2017-09-01 14:51:16Pritish Patilsetmessageid: <1504277476.43.0.203831960923.issue31322@psf.upfronthosting.co.za>
2017-09-01 14:51:16Pritish Patillinkissue31322 messages
2017-09-01 14:51:15Pritish Patilcreate