Fix copying when having watchers on e.g. bounds on inherited Parameter types #675
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When exposing a parameter with Panel, it might be watched for changes in its
bounds
. Suppose you later want to make adeepcopy
of this parameter. This will work fine if the parameter is aNumber
, but not if it is e.g. anInteger
, per this example:As I see it, this issue is due to
Parameter.__setattr__
only checking for slot attributes in the class in question itself, and not its superclasses:param/param/parameterized.py
Line 1120 in 10fff77
In the case of
Integer
, thebounds
attribute is part of__slots__
inNumber
, but not inInteger
, later resulting in the error above.Proposed solution
Use
get_all_slots
to traverse up the class hierarchy and see if the attribute is part of any superclass'__slots__
.This is the shortest fix I could think of, but should this rather be handled by calling the superclasses'
__setattr__
a few rows down?param/param/parameterized.py
Line 1133 in 10fff77
I know too little about the nuances of Param to tell. However, the approach does not seem to break any tests.
I would love to have this solved, so please chime in on how we can do it the best way possible 😃