Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix callbackregistry docstring. #9687

Merged
merged 1 commit into from Nov 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/matplotlib/cbook/__init__.py
Expand Up @@ -255,8 +255,7 @@ def _exception_printer(exc):


class CallbackRegistry(object):
"""Handle registering and disconnecting for a set of signals and
callbacks:
"""Handle registering and disconnecting for a set of signals and callbacks:

>>> def oneat(x):
... print('eat', x)
Expand Down Expand Up @@ -332,9 +331,7 @@ def __setstate__(self, state):
self.__init__(**state)

def connect(self, s, func):
"""
register *func* to be called when a signal *s* is generated
func will be called
"""Register *func* to be called when signal *s* is generated.
Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious to me what the signal s is here, or even what type it should have

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can indeed be anything (hashable):

In [1]: from matplotlib.cbook import CallbackRegistry; cbr = CallbackRegistry()

In [2]: s = object()

In [3]: cbr.connect(s, print)
Out[3]: 1

In [4]: cbr.process(s, "hello world")
hello world

"""
self._func_cid_map.setdefault(s, WeakKeyDictionary())
# Note proxy not needed in python 3.
Expand Down Expand Up @@ -363,8 +360,7 @@ def _remove_proxy(self, proxy):
del self._func_cid_map[signal]

def disconnect(self, cid):
"""
disconnect the callback registered with callback id *cid*
"""Disconnect the callback registered with callback id *cid*.
"""
for eventname, callbackd in list(six.iteritems(self.callbacks)):
try:
Expand All @@ -381,8 +377,10 @@ def disconnect(self, cid):

def process(self, s, *args, **kwargs):
"""
process signal `s`. All of the functions registered to receive
callbacks on `s` will be called with ``**args`` and ``**kwargs``
Process signal *s*.
Copy link
Member

Choose a reason for hiding this comment

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

Again, I'm not sure what s should be here


All of the functions registered to receive callbacks on *s* will be
called with ``*args`` and ``**kwargs``.
"""
if s in self.callbacks:
for cid, proxy in list(six.iteritems(self.callbacks[s])):
Expand Down