From 3d6c9c048636f3dbaef33881307439114a7d6e2a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 9 Apr 2017 02:09:44 -0700 Subject: [PATCH] Allow unhashable keys in AxesStack. They simply will compare unequal to anything else. --- lib/matplotlib/figure.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 7034ea64c0d0..608ceaa99929 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -112,6 +112,8 @@ def add(self, key, a): """ Add Axes *a*, with key *key*, to the stack, and return the stack. + If *key* is unhashable, replace it by a unique, arbitrary object. + If *a* is already on the stack, don't add it again, but return *None*. """ @@ -122,8 +124,7 @@ def add(self, key, a): try: hash(key) except TypeError: - raise ValueError( - "first argument, {!r}, is not a valid key".format(key)) + key = object() a_existing = self.get(key) if a_existing is not None: