param icon indicating copy to clipboard operation
param copied to clipboard

Add SelectorObjects wrapper for forward and backward compatibility

Open philippjfr opened this issue 2 years ago • 2 comments

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

philippjfr avatar Jan 31 '22 17:01 philippjfr

Will need some internal remapping to allow users to subscribe to parameter:objects despite the fact the slot is now called _objects.

philippjfr avatar Jan 31 '22 17:01 philippjfr

Codecov Report

Merging #598 (b6ba65a) into master (7d702ad) will decrease coverage by 1.37%. The diff coverage is 100.00%.

Impacted file tree graph

@@            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.

codecov-commenter avatar Feb 01 '22 12:02 codecov-commenter

@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}

philippjfr avatar Jan 09 '23 11:01 philippjfr

This is ready to merge once we drop py2.7 on main.

philippjfr avatar Mar 12 '23 18:03 philippjfr

Does it fix https://github.com/holoviz/param/issues/398 too?

maximlt avatar Apr 05 '23 09:04 maximlt

Yes, it absolutely should.

philippjfr avatar Apr 05 '23 10:04 philippjfr

Just confirmed that it does.

philippjfr avatar Apr 05 '23 10:04 philippjfr