Skip to content

Name the calling method in opt-in accessor errors - #518

Merged
cpsievert merged 1 commit into
docs-listen-to-docstringsfrom
fix-opt-in-error-method-name
Dec 2, 2026
Merged

cpsievert merged 1 commit into
docs-listen-to-docstringsfrom
fix-opt-in-error-method-name

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Why

plot.selected_rows(df) reads plotly's opt-in selected accessor under a different name. Calling it without opting in raised an error about selected() — a method the caller never wrote:

Before:

`selected()` requires opting in: pass `listen_to=["selected"]` to the renderer. ...

After:

`selected_rows()` requires opting in: pass `listen_to=["selected"]` to the renderer. ...

Direct accessor reads (plot.selected()) are unchanged.

Audited every _read_accessor() call site against the six opt-in accessors (plotly's selected/selecting/brushing/hover, keplergl's config, nglview's camera_orientation); selected_rows() is the only public method that reads one under a different name.

How

Accessors.read() and render_widget_base._read_accessor() take an optional call= naming the method that was actually invoked, used only in the error text — listen_to=[...] still names the underlying accessor. selected_rows() passes call="selected_rows()".

Stacked on #517.

selected_rows(df) reads the opt-in "selected" accessor under a
different name, so a caller who never called selected() got an error
telling them to fix selected() instead of selected_rows(). Accessors.read()
and _read_accessor() now take an optional call= naming the method that
was actually invoked; selected_rows() passes its own name through.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the method-specific accessor error-message change.

No open issues 🎉

What changed in this PR

Improves opt-in accessor errors so Plotly’s selected_rows() names the method the caller used, while still recommending listen_to=["selected"].

Changes:

  • Passes the calling method’s name through accessor reads.
  • Preserves error messages for direct accessor calls.
  • Adds regression tests for both behaviors.
File Description
tests/​unit/​test_plotly_accessors.py Tests method-specific Plotly error messages.
tests/​unit/​test_accessors.py Tests caller-name overrides in accessor errors.
shinywidgets/​_render_widget.py Supplies selected_rows() as the calling method.
shinywidgets/​_render_widget_base.py Forwards the caller name to accessor reads.
shinywidgets/​_accessors.py Uses the caller name in opt-in errors.

Review effort: Balanced

@cpsievert
cpsievert added this pull request to stack #523 December 2, 2026 16:35
@cpsievert
cpsievert merged commit 9acb331 into main Dec 2, 2026
26 of 28 checks passed
@netlify

netlify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for shinywidgets canceled.

Name Link
🔨 Latest commit 256df52
🔍 Latest deploy log https://app.netlify.com/projects/shinywidgets/deploys/6b104a17b18e2c0f9ddfc324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants