param
param copied to clipboard
Add SelectorObjects wrapper for forward and backward compatibility
We have long struggled with an approach to improving Selector
, ListSelector
and ObjectSelector
that would allow users to easily update the objects
. 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 store objects
as a simple list while storing the optional names as a dictionary on the names
attribute. This meant that if you instantiated objects
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 update objects
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 the list
or dict
API to modify the objects
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 in objects
.
Addresses https://github.com/holoviz/param/issues/309 and https://github.com/holoviz/param/issues/331
- [ ] Add tests
- [ ] Update docs
Will need some internal remapping to allow users to subscribe to parameter:objects
despite the fact the slot is now called _objects
.
Codecov Report
Merging #598 (b6ba65a) into master (7d702ad) will decrease coverage by
1.37%
. The diff coverage is100.00%
.
@@ 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
Impacted Files | Coverage Δ | |
---|---|---|
param/parameterized.py | 82.20% <100.00%> (+0.02%) |
:arrow_up: |
numbergen/__init__.py | 76.05% <0.00%> (-3.87%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 7d702ad...b6ba65a. Read the comment docs.
@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}
This is ready to merge once we drop py2.7 on main.
Does it fix https://github.com/holoviz/param/issues/398 too?
Yes, it absolutely should.
Just confirmed that it does.