From 455d2bd6464b7e21aae4bd46c097cecf054c65e3 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Thu, 13 Apr 2017 18:58:09 +0100 Subject: [PATCH] Updated _format_options_error method of OptsMagic --- holoviews/ipython/magics.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index 59f643f56b..c230406b3d 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -636,8 +636,34 @@ def process_element(cls, obj): @classmethod def _format_options_error(cls, err): - info = (err.invalid_keyword, ', '.join(err.allowed_keywords)) - return "Keyword %r not supported by any of the loaded backends. Valid options are :

%s" % info + """ + Return a fuzzy match message string based on the supplied OptionError + """ + allowed_keywords = err.allowed_keywords + target = allowed_keywords.target + matches = allowed_keywords.fuzzy_match(err.invalid_keyword) + if not matches: + matches = allowed_keywords.values + similarity = 'Possible' + else: + similarity = 'Similar' + + loaded_backends = Store.loaded_backends() + target = 'for {0}'.format(target) if target else '' + + if len(loaded_backends) == 1: + loaded=' in loaded backend {0!r}'.format(loaded_backends[0]) + else: + backend_list = ', '.join(['%r'% b for b in loaded_backends[:-1]]) + loaded=' in loaded backends {0} and {1!r}'.format(backend_list, + loaded_backends[-1]) + + msg=('Unexpected keyword {kw} {target}{loaded}.

' + '{similarity} keywords in the currently active ' + '{current_backend} backend are: {matches}') + return msg.format(kw="'%s'" % err.invalid_keyword, target=target, + loaded=loaded, similarity=similarity, + current_backend=repr(Store.current_backend), matches=matches) @classmethod def register_custom_spec(cls, spec):