Skip to content

Commit 1c68b84

Browse files
committed
PEP8 Compliance - All required whitespace fixes
1 parent 3457b1c commit 1c68b84

9 files changed

+387
-176
lines changed

MANIFEST

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# file GENERATED by distutils, do NOT edit
2-
README
32
setup.py
43
src/__init__.py
54
src/underscore.py

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
url='https://github.com/serkanyersen/underscore.py/',
1111
packages=['underscore'],
1212
package_dir={'underscore': 'src'}
13-
)
13+
)

src/underscore.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99

1010

1111
class _IdCounter(object):
12+
1213
""" A Global Dictionary for uniq IDs
1314
"""
1415
count = 0
1516
pass
1617

1718

1819
class __(object):
20+
1921
"""
2022
Use this class to alter __repr__ of
2123
underscore object. So when you are using
2224
it on your project it will make sense
2325
"""
26+
2427
def __init__(self, repr, func):
2528
self._repr = repr
2629
self._func = func
@@ -52,6 +55,7 @@ def _(obj):
5255

5356

5457
class underscore(object):
58+
5559
"""
5660
Instead of creating a class named _ (underscore) I created underscore
5761
So I can use _ function both statically and dynamically just it
@@ -88,6 +92,7 @@ def __init__(self, obj):
8892
self.object = obj
8993

9094
class Namespace(object):
95+
9196
""" For simulating full closure support
9297
"""
9398
pass
@@ -246,7 +251,7 @@ def filter(self, func):
246251
def reject(self, func):
247252
""" Return all the elements for which a truth test fails.
248253
"""
249-
return self._wrap(list(filter(lambda value: not func(value), self.obj)))
254+
return self._wrap(list(filter(lambda val: not func(val), self.obj)))
250255

251256
def all(self, func=None):
252257
""" Determine whether all of the elements match a truth test.
@@ -315,7 +320,8 @@ def pluck(self, key):
315320

316321
def where(self, attrs=None, first=False):
317322
"""
318-
Convenience version of a common use case of `filter`: selecting only objects
323+
Convenience version of a common use case of `filter`:
324+
selecting only objects
319325
containing specific `key:value` pairs.
320326
"""
321327
if attrs is None:
@@ -336,7 +342,8 @@ def by(val, *args):
336342

337343
def findWhere(self, attrs=None):
338344
"""
339-
Convenience version of a common use case of `find`: getting the first object
345+
Convenience version of a common use case of `find`:
346+
getting the first object
340347
containing specific `key:value` pairs.
341348
"""
342349
return self._wrap(self._clean.where(attrs, True))
@@ -422,8 +429,8 @@ def by(result, key, value):
422429

423430
def indexBy(self, val=None):
424431
"""
425-
Indexes the object's values by a criterion, similar to `groupBy`, but for
426-
when you know that your index values will be unique.
432+
Indexes the object's values by a criterion, similar to
433+
`groupBy`, but for when you know that your index values will be unique.
427434
"""
428435
if val is None:
429436
val = lambda *args: args[0]
@@ -746,8 +753,8 @@ def bind(self, context):
746753

747754
def partial(self, *args):
748755
"""
749-
Partially apply a function by creating a version that has had some of its
750-
arguments pre-filled, without changing its dynamic `this` context.
756+
Partially apply a function by creating a version that has had some of
757+
its arguments pre-filled, without changing its dynamic `this` context.
751758
"""
752759
def part(*args2):
753760
args3 = args + args2
@@ -797,8 +804,7 @@ def defer(self, *args):
797804
Defers a function, scheduling it to run after
798805
the current call stack has cleared.
799806
"""
800-
## I know! this isn't really a defer in python. I'm open to suggestions
801-
#######################################################################
807+
# I know! this isn't really a defer in python. I'm open to suggestions
802808
return self.delay(1, *args)
803809

804810
def throttle(self, wait):
@@ -953,7 +959,9 @@ def pairs(self):
953959
return self._wrap(pairs)
954960

955961
def invert(self):
956-
""" Invert the keys and values of an object. The values must be serializable.
962+
"""
963+
Invert the keys and values of an object.
964+
The values must be serializable.
957965
"""
958966
keys = self._clean.keys()
959967
inverted = {}
@@ -1281,7 +1289,9 @@ def identity(self, *args):
12811289
return self._wrap(self.obj)
12821290

12831291
def property(self):
1284-
""" For easy creation of iterators that pull specific properties from objects.
1292+
"""
1293+
For easy creation of iterators that pull
1294+
specific properties from objects.
12851295
"""
12861296
return self._wrap(lambda obj, *args: obj[self.obj])
12871297

@@ -1302,7 +1312,6 @@ def ret(obj, *args):
13021312

13031313
return self._wrap(ret)
13041314

1305-
13061315
def times(self, func, *args):
13071316
""" Run a function **n** times.
13081317
"""
@@ -1583,9 +1592,9 @@ def value(self):
15831592
def makeStatic():
15841593
""" Provide static access to underscore class
15851594
"""
1595+
p = lambda value: inspect.ismethod(value) or inspect.isfunction(value)
15861596
for eachMethod in inspect.getmembers(underscore,
1587-
predicate=lambda value: inspect.ismethod(value) or
1588-
inspect.isfunction(value)):
1597+
predicate=p):
15891598
m = eachMethod[0]
15901599
if not hasattr(_, m):
15911600
def caller(a):

tests/test_arrays.py

+79-30
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,92 @@ def test_compact(self):
3636

3737
def test_flatten(self):
3838
llist = [1, [2], [3, [[[4]]]]]
39-
self.assertEqual(_.flatten(llist), [1, 2, 3, 4], 'can flatten nested arrays')
40-
self.assertEqual(_.flatten(llist, True), [1, 2, 3, [[[4]]]], 'can shallowly flatten nested arrays')
39+
self.assertEqual(_.flatten(llist),
40+
[1, 2, 3, 4], 'can flatten nested arrays')
41+
self.assertEqual(_.flatten(llist, True),
42+
[1, 2, 3, [[[4]]]], 'can shallowly'
43+
' flatten nested arrays')
4144

4245
def test_uniq(self):
4346
tlist = [1, 2, 1, 3, 1, 4]
44-
self.assertEqual([1, 2, 3, 4], _.uniq(tlist), 'can find the unique values of an unsorted array')
47+
self.assertEqual([1, 2, 3, 4], _.uniq(tlist),
48+
'can find the unique values of an unsorted array')
4549

4650
tlist = [1, 1, 1, 2, 2, 3]
47-
self.assertEqual([1, 2, 3], _.uniq(tlist, True), 'can find the unique values of a sorted array faster')
51+
self.assertEqual([1, 2, 3], _.uniq(tlist, True),
52+
'can find the unique values of a sorted array faster')
4853

49-
tlist = [{"name": 'moe'}, {"name": 'curly'}, {"name": 'larry'}, {"name": 'curly'}]
54+
tlist = [{"name": 'moe'}, {"name": 'curly'},
55+
{"name": 'larry'}, {"name": 'curly'}]
5056
iterator = lambda value, *args: value.get('name')
51-
self.assertEqual(["moe", "curly", "larry"], _.uniq(tlist, False, iterator), 'can find the unique values of an array using a custom iterator')
57+
self.assertEqual(
58+
["moe", "curly", "larry"], _.uniq(tlist, False, iterator),
59+
'can find the unique values of an array using a custom iterator')
5260

5361
tlist = [1, 2, 2, 3, 4, 4]
5462
iterator = lambda value, *args: value + 1
55-
self.assertEqual([2, 3, 4, 5], _.uniq(tlist, True, iterator), 'iterator works with sorted array')
63+
self.assertEqual([2, 3, 4, 5], _.uniq(tlist, True, iterator),
64+
'iterator works with sorted array')
5665

5766
def test_without(self):
5867
tlist = [1, 2, 1, 0, 3, 1, 4]
59-
self.assertEqual([2, 3, 4], _.without(tlist, 0, 1), 'can remove all instances of an object')
68+
self.assertEqual([2, 3, 4], _.without(tlist, 0, 1),
69+
'can remove all instances of an object')
6070

6171
tlist = [{"one": 1}, {"two": 2}]
6272

63-
self.assertTrue(len(_.without(tlist, {"one": 1})) == 2, 'uses real object identity for comparisons.')
73+
self.assertTrue(len(_.without(tlist, {"one": 1}))
74+
== 2, 'uses real object identity for comparisons.')
6475
self.assertTrue(len(_.without(tlist, tlist[0])) == 1, 'ditto.')
6576

6677
def test_intersection(self):
6778
stooges = ['moe', 'curly', 'larry'],
6879
leaders = ['moe', 'groucho']
69-
self.assertEqual(['moe'], _.intersection(stooges, leaders), 'can take the set intersection of two string arrays')
70-
self.assertEqual([1, 2], _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]), 'can take the set intersection of two int arrays')
71-
self.assertEqual(['moe'], _(stooges).intersection(leaders), 'can perform an OO-style intersection')
80+
self.assertEqual(['moe'], _.intersection(stooges, leaders),
81+
'can take the set intersection of two string arrays')
82+
self.assertEqual(
83+
[1, 2], _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]),
84+
'can take the set intersection of two int arrays')
85+
self.assertEqual(['moe'], _(stooges).intersection(leaders),
86+
'can perform an OO-style intersection')
7287

7388
def test_union(self):
7489
result = _.union([1, 2, 3], [2, 30, 1], [1, 40])
75-
self.assertEqual([1, 2, 3, 30, 40], result, 'takes the union of a list of arrays')
90+
self.assertEqual([1, 2, 3, 30, 40], result,
91+
'takes the union of a list of arrays')
7692

7793
result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]])
78-
self.assertEqual([1, 2, 3, 30, 40, [1]], result, 'takes the union of a list of nested arrays')
94+
self.assertEqual([1, 2, 3, 30, 40, [1]], result,
95+
'takes the union of a list of nested arrays')
7996

8097
def test_difference(self):
8198
result = _.difference([1, 2, 3], [2, 30, 40])
8299
self.assertEqual([1, 3], result, 'takes the difference of two arrays')
83100

84101
result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111])
85-
self.assertEqual([3, 4], result, 'takes the difference of three arrays')
102+
self.assertEqual([3, 4], result,
103+
'takes the difference of three arrays')
86104

87105
def test_zip(self):
88106
names = ['moe', 'larry', 'curly']
89107
ages = [30, 40, 50]
90108
leaders = [True]
91109
stooges = list(_(names).zip(ages, leaders))
92-
self.assertEqual("[('moe', 30, True), ('larry', 40, None), ('curly', 50, None)]", str(stooges), 'zipped together arrays of different lengths')
110+
self.assertEqual("[('moe', 30, True), ('larry', 40, None),"
111+
" ('curly', 50, None)]", str(
112+
stooges), 'zipped together arrays of different lengths')
93113

94114
def test_zipObject(self):
95115
result = _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50])
96116
shouldBe = {"moe": 30, "larry": 40, "curly": 50}
97-
self.assertEqual(result, shouldBe, "two arrays zipped together into an object")
117+
self.assertEqual(result, shouldBe,
118+
"two arrays zipped together into an object")
98119

99120
def test_indexOf(self):
100121
numbers = [1, 2, 3]
101-
self.assertEqual(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function')
122+
self.assertEqual(_.indexOf(numbers, 2), 1,
123+
'can compute indexOf, even '
124+
'without the native function')
102125
self.assertEqual(_.indexOf(None, 2), -1, 'handles nulls properly')
103126

104127
numbers = [10, 20, 30, 40, 50]
@@ -118,21 +141,47 @@ def test_indexOf(self):
118141

119142
def test_lastIndexOf(self):
120143
numbers = [2, 1, 0, 1, 0, 0, 1, 0, 0, 0]
121-
self.assertEqual(_.lastIndexOf(numbers, 1), 6, 'can compute lastIndexOf, even without the native function')
122-
self.assertEqual(_.lastIndexOf(numbers, 0), 9, 'lastIndexOf the other element')
123-
self.assertEqual(_.lastIndexOf(numbers, 2), 0, 'lastIndexOf the other element')
144+
self.assertEqual(_.lastIndexOf(numbers, 1), 6,
145+
'can compute lastIndexOf, '
146+
'even without the native function')
147+
self.assertEqual(_.lastIndexOf(numbers, 0), 9,
148+
'lastIndexOf the other element')
149+
self.assertEqual(_.lastIndexOf(numbers, 2), 0,
150+
'lastIndexOf the other element')
124151
self.assertEqual(_.indexOf(None, 2), -1, 'handles nulls properly')
125152

126153
def test_range(self):
127-
self.assertEqual(list(_.range(0)), [], 'range with 0 as a first argument generates an empty array')
128-
self.assertEqual(list(_.range(4)), [0, 1, 2, 3], 'range with a single positive argument generates an array of elements 0,1,2,...,n-1')
129-
self.assertEqual(list(_.range(5, 8)), [5, 6, 7], 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1')
130-
self.assertEqual(list(_.range(8, 5)), [], 'range with two arguments a & b, b<a generates an empty array')
131-
self.assertEqual(list(_.range(3, 10, 3)), [3, 6, 9], 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c')
132-
self.assertEqual(list(_.range(3, 10, 15)), [3], 'range with three arguments a & b & c, c > b-a, a < b generates an array with a single element, equal to a')
133-
self.assertEqual(list(_.range(12, 7, -2)), [12, 10, 8], 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b')
134-
self.assertEqual(list(_.range(0, -10, -1)), [0, -1, -2, -3, -4, -5, -6, -7, -8, -9], 'final example in the Python docs')
154+
self.assertEqual(
155+
list(_.range(0)), [], 'range with 0 as a first argument'
156+
' generates an empty array')
157+
self.assertEqual(list(_.range(4)), [0, 1, 2, 3],
158+
'range with a single positive argument generates'
159+
' an array of elements 0,1,2,...,n-1')
160+
self.assertEqual(list(_.range(5, 8)),
161+
[5, 6, 7], 'range with two arguments a & b,'
162+
' a<b generates an array of elements '
163+
' a,a+1,a+2,...,b-2,b-1')
164+
self.assertEqual(list(_.range(8, 5)),
165+
[], 'range with two arguments a & b, b<a'
166+
' generates an empty array')
167+
self.assertEqual(list(_.range(3, 10, 3)),
168+
[3, 6, 9], 'range with three arguments a & b'
169+
' & c, c < b-a, a < b generates an array '
170+
' of elements a,a+c,a+2c,...,b - (multiplier of a) '
171+
' < c')
172+
self.assertEqual(list(_.range(3, 10, 15)),
173+
[3], 'range with three arguments a & b &'
174+
' c, c > b-a, a < b generates an array with '
175+
'a single element, equal to a')
176+
self.assertEqual(list(_.range(12, 7, -2)), [12, 10, 8],
177+
'range with three arguments a & b & c, a'
178+
' > b, c < 0 generates an array of elements'
179+
' a,a-c,a-2c and ends with the number not less than b')
180+
self.assertEqual(list(_.range(0, -10, -1)),
181+
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9], 'final'
182+
' example in the Python docs')
135183

136184
if __name__ == "__main__":
137-
print ("run these tests by executing `python -m unittest discover` in unittests folder")
185+
print("run these tests by executing `python -m unittest"
186+
" discover` in unittests folder")
138187
unittest.main()

0 commit comments

Comments
 (0)