8000 Deprecate cbook.is_hashable. by anntzer · Pull Request #13602 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate cbook.is_hashable. #13602

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

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2019-03-06-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

``cbook.is_hashable`` is deprecated (use
``isinstance(..., collections.abc.Hashable)`` instead).
1 change: 1 addition & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
0