8000 Backport PR #13602: Deprecate cbook.is_hashable. · matplotlib/matplotlib@e64f0ef · GitHub
[go: up one dir, main page]

Skip to content

Commit e64f0ef

Browse files
jklymakMeeseeksDev[bot]
authored andcommitted
Backport PR #13602: Deprecate cbook.is_hashable.
1 parent cae8566 commit e64f0ef

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``cbook.is_hashable`` is deprecated (use
5+
``isinstance(..., collections.abc.Hashable)`` instead).

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def iterable(obj):
350350
return True
351351

352352

353+
@deprecated("3.1", alternative="isinstance(..., collections.abc.Hashable)")
353354
def is_hashable(obj):
354355
"""Returns true if *obj* can be hashed"""
355356
try:

lib/matplotlib/legend.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,15 @@ def get_legend_handler(legend_handler_map, orig_handle):
754754
method-resolution-order. If no matching key is found, it
755755
returns ``None``.
756756
"""
757-
if is_hashable(orig_handle):
758-
try:
759-
return legend_handler_map[orig_handle]
760-
except KeyError:
761-
pass
762-
757+
try:
758+
return legend_handler_map[orig_handle]
759+
except (TypeError, KeyError): # TypeError if unhashable.
760+
pass
763761
for handle_type in type(orig_handle).mro():
764762
try:
765763
return legend_handler_map[handle_type]
766764
except KeyError:
767765
pass
768-
769766
return None
770767

771768
def _init_legend_box(self, handles, labels, markerfirst=True):

0 commit comments

Comments
 (0)
0