Skip to content

CallbackRegistry should not silently drop duplicate callbacks #20210

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy