diff --git a/doc/api/next_api_changes/2019-03-06-AL.rst b/doc/api/next_api_changes/2019-03-06-AL.rst new file mode 100644 index 000000000000..abc8508719df --- /dev/null +++ b/doc/api/next_api_changes/2019-03-06-AL.rst @@ -0,0 +1,5 @@ +Deprecations +```````````` + +``cbook.is_hashable`` is deprecated (use +``isinstance(..., collections.abc.Hashable)`` instead). diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 258884157b27..248ceb524b29 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -350,6 +350,7 @@ def iterable(obj): return True +@deprecated("3.1", alternative="isinstance(..., collections.abc.Hashable)") def is_hashable(obj): """Returns true if *obj* can be hashed""" try: diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index d2c07f562478..3f5e2928c779 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -754,18 +754,15 @@ def get_legend_handler(legend_handler_map, orig_handle): method-resolution-order. If no matching key is found, it returns ``None``. """ - if is_hashable(orig_handle): - try: - return legend_handler_map[orig_handle] - except KeyError: - pass - + try: + return legend_handler_map[orig_handle] + except (TypeError, KeyError): # TypeError if unhashable. + pass for handle_type in type(orig_handle).mro(): try: return legend_handler_map[handle_type] except KeyError: pass - return None def _init_legend_box(self, handles, labels, markerfirst=True):