Skip to content

Commit ed7aa57

Browse files
committed
-
1 parent 5e13c29 commit ed7aa57

File tree

13 files changed

+37
-38
lines changed

13 files changed

+37
-38
lines changed

source_py2/python_toolbox/nifty_collections/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .ordered_set import OrderedSet
88
from .weak_key_default_dict import WeakKeyDefaultDict
99
from .weak_key_identity_dict import WeakKeyIdentityDict
10-
from .counter import Counter
1110
from .lazy_tuple import LazyTuple
1211

1312
from .emitting_ordered_set import EmittingOrderedSet

source_py2/python_toolbox/nifty_collections/weak_key_default_dict.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from weakref import ref
1313

1414

15-
class WeakKeyDefaultDict(UserDict.UserDict, object): #todo: needs testing
15+
#todo: needs testing
16+
class WeakKeyDefaultDict(UserDict.UserDict, object):
1617
'''
1718
A weak key dictionary which can use a default factory.
1819
@@ -91,8 +92,8 @@ def __reduce__(self):
9192
9293
This API is used by pickle.py and copy.py.
9394
"""
94-
return \
95-
(type(self), (self.default_factory,), None, None, self.iteritems())
95+
return (type(self), (self.default_factory,), None, None,
96+
self.iteritems())
9697

9798

9899
def __delitem__(self, key):
@@ -236,4 +237,7 @@ def update(self, dict=None, **kwargs):
236237
if len(kwargs):
237238
self.update(kwargs)
238239

239-
240+
241+
def __len__(self):
242+
return len(self.data)
243+

source_py2/python_toolbox/nifty_collections/weak_key_identity_dict.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __setitem__(self, key, value):
7070
def copy(self):
7171
""" D.copy() -> a shallow copy of D """
7272
new = WeakKeyIdentityDict()
73-
for key, value in self.data.items():
73+
for key, value in self.data.iteritems():
7474
o = key()
7575
if o is not None:
7676
new[o] = value
@@ -194,7 +194,12 @@ def update(self, dict=None, **kwargs):
194194
if dict is not None:
195195
if not hasattr(dict, "items"):
196196
dict = type({})(dict)
197-
for key, value in dict.items():
197+
for key, value in dict.iteritems():
198198
d[IdentityRef(key, self._remove)] = value
199199
if len(kwargs):
200200
self.update(kwargs)
201+
202+
203+
def __len__(self):
204+
return len(self.data)
205+

source_py2/python_toolbox/sleek_reffing/sleek_ref.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
'''
99

1010
import weakref
11-
import UserDict
1211

1312
from python_toolbox import cute_inspect
1413

source_py3/python_toolbox/arguments_profile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from python_toolbox.nifty_collections import OrderedDict
1313
from python_toolbox import dict_tools
1414
from python_toolbox import comparison_tools
15-
import collections
1615

1716

1817
class ArgumentsProfile(object):
@@ -93,7 +92,7 @@ def __init__(self, function, *args, **kwargs):
9392
`*args` and `**kwargs` are the arguments that go into the `function`.
9493
'''
9594

96-
if not isinstance(function, collections.Callable):
95+
if not callable(function):
9796
raise Exception('%s is not a callable object.' % function)
9897
self.function = function
9998

@@ -160,7 +159,7 @@ def __init__(self, function, *args, **kwargs):
160159
else []
161160

162161
# `dict` that maps from argument name to default value:
163-
defaults = OrderedDict(list(zip(defaultful_args, s_defaults)))
162+
defaults = OrderedDict(zip(defaultful_args, s_defaults))
164163

165164
defaultful_args_differing_from_defaults = set((
166165
defaultful_arg for defaultful_arg in defaultful_args

source_py3/python_toolbox/nifty_collections/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33

44
'''Defines various data types, similarly to the stdlib's `collections`.'''
55

6-
import collections
7-
8-
96
from .ordered_dict import OrderedDict
107
from .ordered_set import OrderedSet
118
from .weak_key_default_dict import WeakKeyDefaultDict
129
from .weak_key_identity_dict import WeakKeyIdentityDict
1310
from .lazy_tuple import LazyTuple
1411

1512
from .emitting_ordered_set import EmittingOrderedSet
16-
from .emitting_weak_key_default_dict import EmittingWeakKeyDefaultDict
17-
18-
Counter = collections.Counter
13+
from .emitting_weak_key_default_dict import EmittingWeakKeyDefaultDict

source_py3/python_toolbox/nifty_collections/ordered_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import collections
1212

13-
KEY, PREV, NEXT = list(range(3))
13+
KEY, PREV, NEXT = range(3)
1414

1515

1616
class OrderedSet(collections.MutableSet):
@@ -74,7 +74,7 @@ def pop(self, last=True):
7474
"""Remove and return an arbitrary set element."""
7575
if not self:
7676
raise KeyError('set is empty')
77-
key = next(reversed(self)) if last else next(iter(self))
77+
key = next(reversed(self) if last else iter(self))
7878
self.discard(key)
7979
return key
8080

source_py3/python_toolbox/nifty_collections/weak_key_default_dict.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
'''
99
# todo: revamp
1010

11-
from weakref import ref
1211
import 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

source_py3/python_toolbox/nifty_collections/weak_key_identity_dict.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __hash__(self):
2727
return self._hash
2828

2929

30-
class WeakKeyIdentityDict(collections.MutableMapping, object):
30+
class WeakKeyIdentityDict(collections.MutableMapping):
3131
"""
3232
A weak key dictionary which cares about the keys' identities.
3333
@@ -70,7 +70,7 @@ def __setitem__(self, key, value):
7070
def copy(self):
7171
""" D.copy() -> a shallow copy of D """
7272
new = WeakKeyIdentityDict()
73-
for key, value in list(self.data.items()):
73+
for key, value in self.data.items():
7474
o = key()
7575
if o is not None:
7676
new[o] = value
@@ -194,11 +194,12 @@ def update(self, dict=None, **kwargs):
194194
if dict is not None:
195195
if not hasattr(dict, "items"):
196196
dict = type({})(dict)
197-
for key, value in list(dict.items()):
197+
for key, value in dict.items():
198198
d[IdentityRef(key, self._remove)] = value
199199
if len(kwargs):
200200
self.update(kwargs)
201201

202+
202203
def __len__(self):
203204
return len(self.data)
204205

source_py3/python_toolbox/sleek_reffing/sleek_ref.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
'''
99

1010
import weakref
11-
import collections
1211

1312
from python_toolbox import cute_inspect
1413

1514
from .exceptions import SleekRefDied
16-
import collections
1715

1816

1917
__all__ = ['SleekRef']
@@ -54,7 +52,7 @@ def __init__(self, thing, callback=None):
5452
weakreffable objects.)
5553
'''
5654
self.callback = callback
57-
if callback and not isinstance(callback, collections.Callable):
55+
if callback and not callable(callback):
5856
raise TypeError('%s is not a callable object.' % callback)
5957

6058
self.is_none = (thing is None)

0 commit comments

Comments
 (0)