8000 CallbackRegistry should not silently drop duplicate callbacks · Issue #20210 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
CallbackRegistry should not silently drop duplicate callbacks #20210
Open
@anntzer

Description

@anntzer

Bug report

Bug summary

Currently, if a same function is connected twice to the same signal and same callbackregisry, the second connection is silently dropped, per

proxy = _weak_or_strong_ref(func, self._remove_proxy)
if proxy in self._func_cid_map[signal]:
return self._func_cid_map[signal][proxy]

This seems not so nice and a bit surprising (as in #15785 (comment)); we should deprecate that behavior and either

  • (preferred) just always perform the connection, even if duplicated; 5694 it's the user's job to keep track of duplicates if they want; or
  • (less preferred) add something like keep_duplicates={None,True,False} where None (default) raises an exception for duplicates, True keeps them, False drops them.

Code for reproduction

for _ in range(2): gcf().canvas.mpl_connect("button_press_event", print)
show()

and click on the canvas.

Actual outcome

The event is printed once.

Expected outcome

The event is printed twice.

Matplotlib version

  • Operating system: linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): HEAD (3.4.x+)
  • Matplotlib backend (print(matplotlib.get_backend())): any
  • Python version: 39
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0