diff --git a/google/colab/output/__init__.py b/google/colab/output/__init__.py index 3c73fc5c..dd57e9d5 100644 --- a/google/colab/output/__init__.py +++ b/google/colab/output/__init__.py @@ -14,7 +14,7 @@ """Colabs output package.""" # pylint: disable=g-multiple-import from google.colab.output._area import redirect_to_element, to_default_area, to_footer_area, to_header_area -from google.colab.output._js import eval_js, register_callback +from google.colab.output._js import eval_js, register_callback, unregister_callback from google.colab.output._tags import clear, temporary, use_tags from google.colab.output._util import serve_kernel_port_as_iframe, serve_kernel_port_as_window -from google.colab.output._widgets import enable_custom_widget_manager, disable_custom_widget_manager +from google.colab.output._widgets import disable_custom_widget_manager, enable_custom_widget_manager diff --git a/google/colab/output/_js.py b/google/colab/output/_js.py index 52909ffd..9c0e2387 100644 --- a/google/colab/output/_js.py +++ b/google/colab/output/_js.py @@ -61,6 +61,23 @@ def register_callback(function_name, callback): _functions[function_name] = callback +def unregister_callback(function_name): + """Removes a function previously registered by register_callback. + + Args: + function_name: string + + Raises: + ValueError: if a callback is not currently registered to function_name. + """ + try: + del _functions[function_name] + except KeyError as e: + raise ValueError( + f'Callback function not registered: {function_name}.' + ) from e + + def _invoke_function(function_name, json_args, json_kwargs): """Invokes callback with given function_name.