-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add SelectorObjects wrapper for forward and backward compatibility #598
Conversation
ad6fe8c
to
65bdc52
Compare
Will need some internal remapping to allow users to subscribe to |
Codecov Report
@@ Coverage Diff @@
## master #598 +/- ##
==========================================
- Coverage 81.95% 80.57% -1.38%
==========================================
Files 4 4
Lines 3020 3110 +90
==========================================
+ Hits 2475 2506 +31
- Misses 545 604 +59
Continue to review full report at Codecov.
|
b6ba65a
to
4066393
Compare
@jbednar This is ready for review. I would suggest instead of reviewing the code, review the test cases and check whether they match your understanding and intuitions. One thing to note is that I've decided to allow dictionary style updates to list-like objects by upgrading the list to a dictionary, i.e. you can do something like this: >>> p.selector.objects = ['A', 'B', 'C']
>>> p.selector.objects['D'] = 4
>>> dict(p.selector.objects)
{'A': 'A', 'B': 'B', 'C': 'C', 'D': 4} |
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.
Looks good to me. I have to admit that my eyes glazed over both on the list/dict methods and on the tests; they all look reasonable but I have low confidence I'd detect any problems. I think we'll have to test this with lots of existing code to see if we find any problems. Have you tried it against the Panel test suite?
Co-authored-by: James A. Bednar <jbednar@continuum.io>
Co-authored-by: James A. Bednar <jbednar@continuum.io>
This is ready to merge once we drop py2.7 on main. |
Does it fix #398 too? |
Yes, it absolutely should. |
Just confirmed that it does. |
self.names = objects | ||
self._objects = list(objects.values()) | ||
else: | ||
self.names = {} |
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 default value of names
is now an empty dict when objects
is a list, instead of None
. The test suite fails now, since I added a bunch of tests that check the default values.
Seems like this change was intentional, @philippjfr can you confirm? If so, I can update the tests accordingly.
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.
I assumed this was an intentional change and updated the tests accordingly. Can always amend before 2.0 is release if need be.
We have long struggled with an approach to improving
Selector
,ListSelector
andObjectSelector
that would allow users to easily update theobjects
. Due to unfortunate past decisions this is quite difficult because users can supply both a list or a dict in the constructor and we decided to storeobjects
as a simple list while storing the optional names as a dictionary on thenames
attribute. This meant that if you instantiatedobjects
as a dictionary you had to manage updates to both of these attributes at the same time.To handle this issue we create a wrapper object around the
objects
attribute which has hybrid behavior that allows both list-like and dict-like updates and warns appropriately if for instance you are trying to updateobjects
with the list-like API but have supplied names for other objects previously. An additional benefit of this wrapper object is that if you use any of thelist
ordict
API to modify theobjects
we can trigger an event, while in the past a user would manually have to trigger such an event if they wanted Panel or some other downstream library to update in response to the change inobjects
.Fixes #309
Fixes #331
Fixes #645
Fixes #398