-
Notifications
You must be signed in to change notification settings - Fork 85
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
Fix cloning issue with container traits #1624
Conversation
@sallenEnth Interested in reviewing? (Feel free to unassign yourself from review if not.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution is actually simpler than I thought. I noticed that TraitListObject
had already situation where object
was lambda: None
. Thank you for the work @mdickinson.
LGTM, but I still does not have a very deep knowledge of Traits. I have some minor suggestions for changes/additions to the regression tests.
Co-authored-by: Steve Allen <sallen@enthought.com>
Co-authored-by: Steve Allen <sallen@enthought.com>
Apologies - looks like I'm wrong about this. So let's keep that test (thank you!), and I need to figure out how this is working when I expected it to fail ... |
Got it: the resulting |
This PR makes a shallow fix for problems with
clone_traits
applied toList
,Dict
andSet
traits. It doesn't try to touch deeper issues of disconnection ofTraitsListObject
,TraitDictObject
and friends from their owningHasTraits
object.Closes #1622. The cause of that issue is that we were using a function
lambda: None
forobject
where aHasTraits
object was expected. InsideTraitListObject
we then take a weakref to that function. In most cases, thelambda
function has no other references to it, so it's garbage collected immediately and when the weakref is dereferenced, it returnsNone
. But in the deepcopy case the weakref target is kept alive for long enough that we try to use the actuallambda: None
function as aHasTraits
object. The solution is to allow and special-case an object ofNone
in theTraitListObject
constructor.