88'''
99# todo: revamp
1010
11- from weakref import ref
1211import collections
12+ from weakref import ref
1313
1414
1515#todo: needs testing
16- class WeakKeyDefaultDict (collections .MutableMapping , object ):
16+ class WeakKeyDefaultDict (collections .MutableMapping ):
1717 '''
1818 A weak key dictionary which can use a default factory.
1919
@@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
3636 self .default_factory = None
3737 if 'default_factory' in kwargs :
3838 self .default_factory = kwargs .pop ('default_factory' )
39- elif len (args ) > 0 and isinstance (args [0 ], collections . Callable ):
39+ elif len (args ) > 0 and callable (args [0 ]):
4040 self .default_factory = args [0 ]
4141 args = args [1 :]
4242
@@ -92,8 +92,8 @@ def __reduce__(self):
9292
9393 This API is used by pickle.py and copy.py.
9494 """
95- return \
96- ( type ( self ), ( self . default_factory ,), None , None , iter (self .items ()))
95+ return ( type ( self ), ( self . default_factory ,), None , None ,
96+ iter (self .items ()))
9797
9898
9999 def __delitem__ (self , key ):
@@ -232,11 +232,12 @@ def update(self, dict=None, **kwargs):
232232 if dict is not None :
233233 if not hasattr (dict , "items" ):
234234 dict = type ({})(dict )
235- for key , value in list ( dict .items () ):
235+ for key , value in dict .items ():
236236 d [ref (key , self ._remove )] = value
237237 if len (kwargs ):
238238 self .update (kwargs )
239239
240+
240241 def __len__ (self ):
241242 return len (self .data )
242243
0 commit comments