From 8ed324e798273346ff1d7b0f317cd271f7c0b939 2017-10-05 08:38:56 From: Fabio Niephaus Date: 2017-10-05 08:38:56 Subject: [PATCH] Ensure `function` is actually a function. Plus minor cleanup --- diff --git a/IPython/core/events.py b/IPython/core/events.py index a3b9467..8dfc59b 100644 --- a/IPython/core/events.py +++ b/IPython/core/events.py @@ -14,6 +14,7 @@ events and the arguments which will be passed to them. """ from functools import wraps +from inspect import isfunction try: from inspect import getfullargspec except: @@ -79,10 +80,10 @@ class EventManager(object): raise TypeError('Need a callable, got %r' % function) callback_proto = available_events.get(event) - if (callable(callback_proto) and + if (isfunction(callback_proto) and isfunction(function) and len(getfullargspec(callback_proto).args) > 0 and len(getfullargspec(function).args) == 0): - # `callback_proto` requires args but `function` does not, so a + # `callback_proto` has args but `function` does not, so a # compatibility wrapper is needed. self.callbacks[event].append(_compatibility_wrapper_for(function)) else: diff --git a/docs/source/config/callbacks.rst b/docs/source/config/callbacks.rst index a71d693..e15d136 100644 --- a/docs/source/config/callbacks.rst +++ b/docs/source/config/callbacks.rst @@ -70,11 +70,9 @@ argument, even though the actual result is not yet available. post_run_cell ------------- -``post_run_cell`` runs after interactive execution. -It can be used to cleanup or notify or perform operations on any side effects -produced during execution. -For instance, the inline matplotlib backend uses this event to display any -figures created but not explicitly displayed during the course of the cell. +``post_run_cell`` runs after interactive execution (e.g. a cell in a notebook). +It can be used to cleanup or notify or perform operations on any side effects produced during execution. +For instance, the inline matplotlib backend uses this event to display any figures created but not explicitly displayed during the course of the cell. The object which will be returned as the execution result is provided as an argument. @@ -84,20 +82,6 @@ post_execute The same as ``pre_execute``, ``post_execute`` is like ``post_run_cell``, but fires for *all* executions, not just interactive ones. -finally_run_cell -------------- - -``finally_run_cell`` is like ``post_run_cell``, but fires after *all* executions -(even when, for example, a ``SyntaxError`` was raised). -Additionally, the execution result is provided as an argument. - -finally_execute ------------- - -``finally_execute`` is like ``post_execute``, but fires after *all* executions -(even when, for example, a ``SyntaxError`` was raised). -Additionally, the execution result is provided as an argument. - .. seealso::