Skip to content

fix: swev-id: matplotlib__matplotlib-25311 align draggable pickling callbacks#55

Open
casey-brooks wants to merge 1 commit intomatplotlib__matplotlib-25311from
fix/draggable-pickle-25311
Open

fix: swev-id: matplotlib__matplotlib-25311 align draggable pickling callbacks#55
casey-brooks wants to merge 1 commit intomatplotlib__matplotlib-25311from
fix/draggable-pickle-25311

Conversation

@casey-brooks
Copy link

Summary

Reproduction steps

import matplotlib.pyplot as plt
import pickle

fig, ax = plt.subplots()
(line,) = ax.plot([0, 1], [0, 1], label="line")
legend = ax.legend()
legend.set_draggable(True)
annotation = ax.annotate("drag me", xy=(0.5, 0.5))
annotation.draggable(True)

fig.canvas.draw()
payload = pickle.dumps(fig, protocol=pickle.HIGHEST_PROTOCOL)
pickle.loads(payload)

Observed failure

Fix

  • add a canvas property in DraggableBase and drop the stored canvas attribute
  • connect picklable handlers for pick, release, and motion during init using _canvas_callbacks, storing partial disconnectors
  • remove the dynamic motion wiring from on_pick/on_release and let disconnect() run the cached disconnectors so pickling can succeed

Upstream references

Testing

  • MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib LD_LIBRARY_PATH=/root/.nix-profile/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/f8w1i7yisixb9hivzbk0l4ixmf67fjqr-gcc-14.3.0-libgcc/lib /workspace/matplotlib/.venv/bin/pytest lib/matplotlib/tests/test_legend.py -k draggable
  • MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib LD_LIBRARY_PATH=/root/.nix-profile/lib:/nix/store/qipd93x9gjyiygqk673rd2ssnf8y7jj0-gcc-14.3.0-lib/lib:/nix/store/f8w1i7yisixb9hivzbk0l4ixmf67fjqr-gcc-14.3.0-libgcc/lib /workspace/matplotlib/.venv/bin/python - <<'PY' ...
  • ✅ Local tests passed

ID: 277

@casey-brooks casey-brooks requested a review from a team December 25, 2025 12:27
@casey-brooks
Copy link
Author

Local Testing

  • ============================= test session starts ==============================
    platform linux -- Python 3.10.19, pytest-9.0.2, pluggy-1.6.0
    rootdir: /workspace/matplotlib
    configfile: pytest.ini
    plugins: timeout-2.4.0, rerunfailures-16.1, xvfb-3.1.1, cov-7.0.0, xdist-3.8.0
    collected 128 items / 125 deselected / 3 selected

lib/matplotlib/tests/test_legend.py ... [100%]

====================== 3 passed, 125 deselected in 0.27s ======================= → 3 passed, 125 deselected

  • → draggable legend/annotation pickle succeeds; no FigureCanvas strings in stream
  • → no lint issues

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Looks good—thanks for aligning the draggable helpers with the upstream pickling fix.

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