aboutsummaryrefslogtreecommitdiff
path: root/Lib/fontTools/misc/dictTools.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/fontTools/misc/dictTools.py')
-rw-r--r--Lib/fontTools/misc/dictTools.py56
1 files changed, 37 insertions, 19 deletions
diff --git a/Lib/fontTools/misc/dictTools.py b/Lib/fontTools/misc/dictTools.py
index ae7932c9..e3c0df73 100644
--- a/Lib/fontTools/misc/dictTools.py
+++ b/Lib/fontTools/misc/dictTools.py
@@ -1,7 +1,8 @@
"""Misc dict tools."""
-__all__ = ['hashdict']
+__all__ = ["hashdict"]
+
# https://stackoverflow.com/questions/1151658/python-hashable-dicts
class hashdict(dict):
@@ -26,36 +27,54 @@ class hashdict(dict):
http://stackoverflow.com/questions/1151658/python-hashable-dicts
"""
+
def __key(self):
return tuple(sorted(self.items()))
+
def __repr__(self):
- return "{0}({1})".format(self.__class__.__name__,
- ", ".join("{0}={1}".format(
- str(i[0]),repr(i[1])) for i in self.__key()))
+ return "{0}({1})".format(
+ self.__class__.__name__,
+ ", ".join("{0}={1}".format(str(i[0]), repr(i[1])) for i in self.__key()),
+ )
def __hash__(self):
return hash(self.__key())
+
def __setitem__(self, key, value):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def __delitem__(self, key):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def clear(self):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def pop(self, *args, **kwargs):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def popitem(self, *args, **kwargs):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def setdefault(self, *args, **kwargs):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
def update(self, *args, **kwargs):
- raise TypeError("{0} does not support item assignment"
- .format(self.__class__.__name__))
+ raise TypeError(
+ "{0} does not support item assignment".format(self.__class__.__name__)
+ )
+
# update is not ok because it mutates the object
# __add__ is ok because it creates a new object
# while the new object is under construction, it's ok to mutate it
@@ -63,4 +82,3 @@ class hashdict(dict):
result = hashdict(self)
dict.update(result, right)
return result
-