Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepcopy of fpointers list #160

Open
mguijarr opened this issue May 13, 2020 · 0 comments
Open

deepcopy of fpointers list #160

mguijarr opened this issue May 13, 2020 · 0 comments

Comments

@mguijarr
Copy link

mguijarr commented May 13, 2020

First of all, thanks a lot for this library : it is very useful !

Recently at my company we wanted to update to treelib 1.6.1, however we started to have problems
because now everything stored in the tree has to be "picklable", because of the use of copy.deepcopy in the clone_pointers method.

Why using deepcopy, in this case ? 1) I think it is rather inefficient, 2) it really puts an additional constraint on the kind of object in the fpointer list, which was not there before

According to the comment in the corresponding code, this is done to not pass the fpointers list as a reference.

Then, would you consider using shallow copy instead of deepcopy ?

Proposal:

diff --git a/treelib/node.py b/treelib/node.py                                                                                                                               index 6accae1..910d2e2 100644                                                                                                                                                --- a/treelib/node.py                                                                                                                                                        +++ b/treelib/node.py                                                                                                                                                        @@ -217,7 +217,7 @@ class Node(object):                                                                                                                                      
         self.set_predecessor(former_bpointer, new_tree_id)                                                                                                                  
         former_fpointer = self.successors(former_tree_id)                                                                                                                   
         # fpointer is a list and would be copied by reference without deepcopy                                                                                              
-        self.set_successors(copy.deepcopy(former_fpointer), tree_id=new_tree_id)                                                                                            
+        self.set_successors(list(former_fpointer), tree_id=new_tree_id)                                                                                                     
                                                                                                                                                                             
     def reset_pointers(self, tree_id):                                                                                                                                      
         self.set_predecessor(None, tree_id)  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant