Message301112
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__ |
|
Date |
User |
Action |
Args |
2017-09-01 14:51:16 | Pritish Patil | set | recipients:
+ Pritish Patil, docs@python |
2017-09-01 14:51:16 | Pritish Patil | set | messageid: <1504277476.43.0.203831960923.issue31322@psf.upfronthosting.co.za> |
2017-09-01 14:51:16 | Pritish Patil | link | issue31322 messages |
2017-09-01 14:51:15 | Pritish Patil | create | |
|