def get_legend_handler(legend_handler_map, orig_handle): """ Return a legend handler from *legend_handler_map* that corresponds to *orig_handler*. *legend_handler_map* should be a dictionary object (that is returned by the get_legend_handler_map method). It first checks if the *orig_handle* itself is a key in the *legend_hanler_map* and return the associated value. Otherwise, it checks for each of the classes in its 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 for handle_type in type(orig_handle).mro(): try: return legend_handler_map[handle_type] except KeyError: pass return None
def get_legend_handler(legend_handler_map, orig_handle): """ return a legend handler from *legend_handler_map* that corresponds to *orig_handler*. *legend_handler_map* should be a dictionary object (that is returned by the get_legend_handler_map method). It first checks if the *orig_handle* itself is a key in the *legend_hanler_map* and return the associated value. Otherwise, it checks for each of the classes in its 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 for handle_type in type(orig_handle).mro(): try: return legend_handler_map[handle_type] except KeyError: pass return None
def test_is_hashable(): s = 'string' assert cbook.is_hashable(s) lst = ['list', 'of', 'stings'] assert not cbook.is_hashable(lst)
def test_is_hashable(): with pytest.warns(MatplotlibDeprecationWarning): s = 'string' assert cbook.is_hashable(s) lst = ['list', 'of', 'stings'] assert not cbook.is_hashable(lst)
def test_is_hashable(): s = "string" assert cbook.is_hashable(s) lst = ["list", "of", "stings"] assert not cbook.is_hashable(lst)