From 762ec3a0eb083c1c402a8fb81ab812a6025ab597 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 10 Oct 2017 22:14:33 -0700 Subject: [PATCH] structures: fix _keymangle when key isn't a string I really need to add unit tests for these... --- structures.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/structures.py b/structures.py index 5ab6177..4a9acf2 100644 --- a/structures.py +++ b/structures.py @@ -72,7 +72,9 @@ class CaseInsensitiveFixedSet(collections.abc.Set, CopyWrapper): @staticmethod def _keymangle(key): """Converts the given key to lowercase.""" - return key.lower() + if isinstance(key, str): + return key.lower() + return key def __repr__(self): return "%s(%s)" % (self.__class__.__name__, self._data) @@ -121,7 +123,9 @@ class IRCCaseInsensitiveDict(CaseInsensitiveDict): def _keymangle(self, key): """Converts the given key to lowercase.""" - return self._irc.to_lower(key) + if isinstance(key, str): + return self._irc.to_lower(key) + return key def __copy__(self): return self.__class__(self._irc, data=self._data.copy()) @@ -147,7 +151,9 @@ class IRCCaseInsensitiveSet(CaseInsensitiveSet): def _keymangle(self, key): """Converts the given key to lowercase.""" - return self._irc.to_lower(key) + if isinstance(key, str): + return self._irc.to_lower(key) + return key def __copy__(self): return self.__class__(self._irc, data=self._data.copy())