[pypy-commit] pypy remove-tuple-smm: Style fixes.

Manuel Jacob noreply at buildbot.pypy.org
Wed May 22 11:50:08 CEST 2013


Author: Manuel Jacob
Branch: remove-tuple-smm
Changeset: r64430:8da79536cbc4
Date: 2013-05-22 11:22 +0200
http://bitbucket.org/pypy/pypy/changeset/8da79536cbc4/

Log:	Style fixes.

diff --git a/pypy/objspace/std/smalltupleobject.py b/pypy/objspace/std/smalltupleobject.py
--- a/pypy/objspace/std/smalltupleobject.py
+++ b/pypy/objspace/std/smalltupleobject.py
@@ -8,8 +8,8 @@
 
 def make_specialized_class(n):
     iter_n = unrolling_iterable(range(n))
+
     class cls(W_AbstractTupleObject):
-
         def __init__(self, values):
             assert len(values) == n
             for i in iter_n:
@@ -32,7 +32,7 @@
                 index += n
             for i in iter_n:
                 if index == i:
-                    return getattr(self,'w_value%s' % i)
+                    return getattr(self, 'w_value%s' % i)
             raise OperationError(space.w_IndexError,
                                  space.wrap("tuple index out of range"))
 
@@ -42,7 +42,7 @@
             if n != w_other.length():
                 return space.w_False
             for i in iter_n:
-                item1 = getattr(self,'w_value%s' % i)
+                item1 = getattr(self, 'w_value%s' % i)
                 item2 = w_other.getitem(space, i)
                 if not space.eq_w(item1, item2):
                     return space.w_False
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -80,7 +80,7 @@
                 if nValues != w_other.length():
                     return space.w_False
                 for i in iter_n:
-                    myval    = getattr(self,    'value%s' % i)
+                    myval = getattr(self, 'value%s' % i)
                     otherval = w_other.getitem(space, i)
                     if typetuple[i] == object:
                         myval_wrapped = myval
@@ -92,7 +92,7 @@
                     return space.w_True
 
             for i in iter_n:
-                myval    = getattr(self,    'value%s' % i)
+                myval = getattr(self, 'value%s' % i)
                 otherval = getattr(w_other, 'value%s' % i)
                 if typetuple[i] == object:
                     if not self.space.eq_w(myval, otherval):
diff --git a/pypy/objspace/std/test/test_smalltupleobject.py b/pypy/objspace/std/test/test_smalltupleobject.py
--- a/pypy/objspace/std/test/test_smalltupleobject.py
+++ b/pypy/objspace/std/test/test_smalltupleobject.py
@@ -1,8 +1,7 @@
+from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
+from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
 from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
-from pypy.interpreter.error import OperationError
-from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
-from pypy.tool.pytest.objspace import gettestobjspace
+
 
 class AppTestW_SmallTupleObject(AppTestW_TupleObject):
     spaceconfig = {"objspace.std.withsmalltuple": True}
@@ -16,8 +15,8 @@
         """)
 
     def test_smalltuple(self):
-        self.issmall((1,2))
-        self.issmall((1,2,3))
+        self.issmall((1, 2))
+        self.issmall((1, 2, 3))
 
     def test_slicing_to_small(self):
         self.issmall((1, 2, 3)[0:2])    # SmallTuple2
@@ -27,38 +26,39 @@
         self.issmall((1, 2, 3, 4)[0:3:1])
 
     def test_adding_to_small(self):
-        self.issmall((1,)+(2,))       # SmallTuple2
-        self.issmall((1,1)+(2,))      # SmallTuple3
-        self.issmall((1,)+(2,3))
+        self.issmall((1,) + (2,))       # SmallTuple2
+        self.issmall((1, 1) + (2,))      # SmallTuple3
+        self.issmall((1,) + (2, 3))
 
     def test_multiply_to_small(self):
-        self.issmall((1,)*2)
-        self.issmall((1,)*3)
+        self.issmall((1,) * 2)
+        self.issmall((1,) * 3)
 
     def test_slicing_from_small(self):
-        assert (1,2)[0:1:1] == (1,)
-        assert (1,2,3)[0:2:1] == (1,2)
+        assert (1, 2)[0:1:1] == (1,)
+        assert (1, 2, 3)[0:2:1] == (1, 2)
 
     def test_eq(self):
-        a = (1,2,3)
-        b = (1,2,3)
+        a = (1, 2, 3)
+        b = (1, 2, 3)
         assert a == b
 
-        c = (1,3,2)
+        c = (1, 3, 2)
         assert a != c
 
     def test_hash(self):
-        a = (1,2,3)
-        b = (1,2,3)
+        a = (1, 2, 3)
+        b = (1, 2, 3)
         assert hash(a) == hash(b)
 
-        c = (1,3,2)
+        c = (1, 3, 2)
         assert hash(a) != hash(c)
 
     def test_foo(self):
         assert tuple([0]) + (1,) == (0, 1)
         assert not tuple([0]) + (1,) == (0,)
 
+
 class TestW_SmallTupleObject():
     spaceconfig = {"objspace.std.withsmalltuple": True}
 
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -1,10 +1,7 @@
-import py, sys
+from pypy.objspace.std.specialisedtupleobject import _specialisations
+from pypy.objspace.std.test import test_tupleobject
 from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std.specialisedtupleobject import _specialisations
-from pypy.interpreter.error import OperationError
 from pypy.tool.pytest.objspace import gettestobjspace
-from pypy.objspace.std.test import test_tupleobject
-from pypy.interpreter import gateway
 
 
 for cls in _specialisations:
@@ -17,11 +14,11 @@
     def test_isspecialisedtupleobjectintint(self):
         w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
         assert isinstance(w_tuple, W_SpecialisedTupleObject_ii)
-        
+
     def test_isnotspecialisedtupleobject(self):
         w_tuple = self.space.newtuple([self.space.wrap({})])
         assert not 'W_SpecialisedTupleObject' in type(w_tuple).__name__
-        
+
     def test_specialisedtupleclassname(self):
         w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
         assert w_tuple.__class__.__name__ == 'W_SpecialisedTupleObject_ii'
@@ -29,7 +26,7 @@
     def test_hash_against_normal_tuple(self):
         N_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
         S_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
-        
+
         def hash_test(values, must_be_specialized=True):
             N_values_w = [N_space.wrap(value) for value in values]
             S_values_w = [S_space.wrap(value) for value in values]
@@ -42,15 +39,15 @@
             assert S_space.is_true(S_space.eq(N_w_tuple, S_w_tuple))
             assert S_space.is_true(S_space.eq(N_space.hash(N_w_tuple), S_space.hash(S_w_tuple)))
 
-        hash_test([1,2])
-        hash_test([1.5,2.8])
-        hash_test([1.0,2.0])
-        hash_test(['arbitrary','strings'])
-        hash_test([1,(1,2,3,4)])
-        hash_test([1,(1,2)])
-        hash_test([1,('a',2)])
-        hash_test([1,()])
-        hash_test([1,2,3], must_be_specialized=False)
+        hash_test([1, 2])
+        hash_test([1.5, 2.8])
+        hash_test([1.0, 2.0])
+        hash_test(['arbitrary', 'strings'])
+        hash_test([1, (1, 2, 3, 4)])
+        hash_test([1, (1, 2)])
+        hash_test([1, ('a', 2)])
+        hash_test([1, ()])
+        hash_test([1, 2, 3], must_be_specialized=False)
 
 
 class AppTestW_SpecialisedTupleObject:
@@ -88,7 +85,7 @@
         assert len(t) == 2
 
     def test_notspecialisedtuple(self):
-        assert not self.isspecialised((42,43,44,45))
+        assert not self.isspecialised((42, 43, 44, 45))
         assert not self.isspecialised((1.5,))
 
     def test_slicing_to_specialised(self):
@@ -118,66 +115,66 @@
         c = (2, 1)
         assert not a == c
 
-    def test_eq_can_delegate(self):        
-        a = (1,2)
-        b = (1,3,2)
+    def test_eq_can_delegate(self):
+        a = (1, 2)
+        b = (1, 3, 2)
         assert not a == b
 
         values = [2, 2L, 2.0, 1, 1L, 1.0]
         for x in values:
             for y in values:
-                assert ((1,2) == (x,y)) == (1 == x and 2 == y)
+                assert ((1, 2) == (x, y)) == (1 == x and 2 == y)
 
     def test_neq(self):
-        a = (1,2)
+        a = (1, 2)
         b = (1,)
-        b = b+(2,)
+        b = b + (2,)
         assert not a != b
-        
-        c = (1,3)
+
+        c = (1, 3)
         assert a != c
-        
+
     def test_ordering(self):
-        a = (1,2)
-        assert a <  (2,2)    
-        assert a <  (1,3)    
-        assert not a <  (1,2) 
+        a = (1, 2)
+        assert a < (2, 2)
+        assert a < (1, 3)
+        assert not a < (1, 2)
 
-        assert a <=  (2,2)    
-        assert a <=  (1,2) 
-        assert not a <=  (1,1) 
-           
-        assert a >= (0,2)    
-        assert a >= (1,2)    
-        assert not a >= (1,3)    
-        
-        assert a > (0,2)    
-        assert a > (1,1)    
-        assert not a > (1,3)    
+        assert a <= (2, 2)
+        assert a <= (1, 2)
+        assert not a <= (1, 1)
 
-        assert (2,2) > a
-        assert (1,3) > a
-        assert not (1,2) > a
-           
-        assert (2,2) >= a
-        assert (1,2) >= a
-        assert not (1,1) >= a
-           
-        assert (0,2) <= a
-        assert (1,2) <= a
-        assert not (1,3) <= a
-        
-        assert (0,2) < a
-        assert (1,1) < a
-        assert not (1,3) < a
+        assert a >= (0, 2)
+        assert a >= (1, 2)
+        assert not a >= (1, 3)
+
+        assert a > (0, 2)
+        assert a > (1, 1)
+        assert not a > (1, 3)
+
+        assert (2, 2) > a
+        assert (1, 3) > a
+        assert not (1, 2) > a
+
+        assert (2, 2) >= a
+        assert (1, 2) >= a
+        assert not (1, 1) >= a
+
+        assert (0, 2) <= a
+        assert (1, 2) <= a
+        assert not (1, 3) <= a
+
+        assert (0, 2) < a
+        assert (1, 1) < a
+        assert not (1, 3) < a
 
     def test_hash(self):
-        a = (1,2)
+        a = (1, 2)
         b = (1,)
-        b += (2,) # else a and b refer to same constant
+        b += (2,)  # else a and b refer to same constant
         assert hash(a) == hash(b)
 
-        c = (2,4)
+        c = (2, 4)
         assert hash(a) != hash(c)
 
         assert hash(a) == hash((1L, 2L)) == hash((1.0, 2.0)) == hash((1.0, 2L))
diff --git a/pypy/objspace/std/test/test_tupleobject.py b/pypy/objspace/std/test/test_tupleobject.py
--- a/pypy/objspace/std/test/test_tupleobject.py
+++ b/pypy/objspace/std/test/test_tupleobject.py
@@ -1,17 +1,16 @@
-#from __future__ import nested_scopes
+from pypy.interpreter.error import OperationError
 from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.interpreter.error import OperationError
+
 
 class TestW_TupleObject:
-
     def test_is_true(self):
         w = self.space.wrap
         w_tuple = W_TupleObject([])
-        assert self.space.is_true(w_tuple) == False
+        assert self.space.is_true(w_tuple) is False
         w_tuple = W_TupleObject([w(5)])
-        assert self.space.is_true(w_tuple) == True
+        assert self.space.is_true(w_tuple) is True
         w_tuple = W_TupleObject([w(5), w(3)])
-        assert self.space.is_true(w_tuple) == True
+        assert self.space.is_true(w_tuple) is True
 
     def test_len(self):
         w = self.space.wrap
@@ -19,7 +18,7 @@
         assert self.space.eq_w(self.space.len(w_tuple), w(0))
         w_tuple = W_TupleObject([w(5)])
         assert self.space.eq_w(self.space.len(w_tuple), w(1))
-        w_tuple = W_TupleObject([w(5), w(3), w(99)]*111)
+        w_tuple = W_TupleObject([w(5), w(3), w(99)] * 111)
         assert self.space.eq_w(self.space.len(w_tuple), w(333))
 
     def test_getitem(self):
@@ -65,7 +64,7 @@
         w_tuple2 = W_TupleObject([w(-7)] * 111)
         assert self.space.eq_w(self.space.add(w_tuple1, w_tuple1),
                            W_TupleObject([w(5), w(3), w(99),
-                                                      w(5), w(3), w(99)]))
+                                          w(5), w(3), w(99)]))
         assert self.space.eq_w(self.space.add(w_tuple1, w_tuple2),
                            W_TupleObject([w(5), w(3), w(99)] + [w(-7)] * 111))
         assert self.space.eq_w(self.space.add(w_tuple1, w_tuple0), w_tuple1)
@@ -77,7 +76,7 @@
         arg = w(2)
         n = 3
         w_tup = W_TupleObject([arg])
-        w_tup3 = W_TupleObject([arg]*n)
+        w_tup3 = W_TupleObject([arg] * n)
         w_res = self.space.mul(w_tup, w(n))
         assert self.space.eq_w(w_tup3, w_res)
         # commute
@@ -91,26 +90,26 @@
         w = self.space.wrap
 
         def test1(testtuple, start, stop, step, expected):
-            w_slice  = self.space.newslice(w(start), w(stop), w(step))
+            w_slice = self.space.newslice(w(start), w(stop), w(step))
             w_tuple = W_TupleObject([w(i) for i in testtuple])
             w_result = self.space.getitem(w_tuple, w_slice)
             assert self.space.unwrap(w_result) == expected
-        
-        for testtuple in [(), (5,3,99), tuple(range(5,555,10))]:
+
+        for testtuple in [(), (5, 3, 99), tuple(range(5, 555, 10))]:
             for start in [-2, -1, 0, 1, 10]:
                 for end in [-1, 0, 2, 999]:
                     test1(testtuple, start, end, 1, testtuple[start:end])
 
-        test1((5,7,1,4), 3, 1, -2,  (4,))
-        test1((5,7,1,4), 3, 0, -2,  (4, 7))
-        test1((5,7,1,4), 3, -1, -2, ())
-        test1((5,7,1,4), -2, 11, 2, (1,))
-        test1((5,7,1,4), -3, 11, 2, (7, 4))
-        test1((5,7,1,4), -5, 11, 2, (5, 1))
+        test1((5, 7, 1, 4), 3, 1, -2,  (4,))
+        test1((5, 7, 1, 4), 3, 0, -2,  (4, 7))
+        test1((5, 7, 1, 4), 3, -1, -2, ())
+        test1((5, 7, 1, 4), -2, 11, 2, (1,))
+        test1((5, 7, 1, 4), -3, 11, 2, (7, 4))
+        test1((5, 7, 1, 4), -5, 11, 2, (5, 1))
 
     def test_eq(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -126,9 +125,10 @@
                            self.space.w_True)
         assert self.space.eq_w(self.space.eq(w_tuple2, w_tuple3),
                            self.space.w_False)
+
     def test_ne(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -144,9 +144,10 @@
                            self.space.w_False)
         assert self.space.eq_w(self.space.ne(w_tuple2, w_tuple3),
                            self.space.w_True)
+
     def test_lt(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -165,10 +166,10 @@
                            self.space.w_True)
         assert self.space.eq_w(self.space.lt(w_tuple4, w_tuple3),
                            self.space.w_True)
-        
+
     def test_ge(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -187,10 +188,10 @@
                            self.space.w_False)
         assert self.space.eq_w(self.space.ge(w_tuple4, w_tuple3),
                            self.space.w_False)
-        
+
     def test_gt(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -209,10 +210,10 @@
                            self.space.w_False)
         assert self.space.eq_w(self.space.gt(w_tuple4, w_tuple3),
                            self.space.w_False)
-        
+
     def test_le(self):
         w = self.space.wrap
-        
+
         w_tuple0 = W_TupleObject([])
         w_tuple1 = W_TupleObject([w(5), w(3), w(99)])
         w_tuple2 = W_TupleObject([w(5), w(3), w(99)])
@@ -234,28 +235,27 @@
 
 
 class AppTestW_TupleObject:
-
     def test_is_true(self):
         assert not ()
         assert (5,)
-        assert (5,3)
+        assert (5, 3)
 
     def test_len(self):
         assert len(()) == 0
         assert len((5,)) == 1
-        assert len((5,3,99,1,2,3,4,5,6)) == 9 
+        assert len((5, 3, 99, 1, 2, 3, 4, 5, 6)) == 9
 
     def test_getitem(self):
-        assert (5,3)[0] == 5
-        assert (5,3)[1] == 3
-        assert (5,3)[-1] == 3
-        assert (5,3)[-2] == 5
-        raises(IndexError, "(5,3)[2]")
+        assert (5, 3)[0] == 5
+        assert (5, 3)[1] == 3
+        assert (5, 3)[-1] == 3
+        assert (5, 3)[-2] == 5
+        raises(IndexError, "(5, 3)[2]")
         raises(IndexError, "(5,)[1]")
         raises(IndexError, "()[0]")
 
     def test_iter(self):
-        t = (5,3,99)
+        t = (5, 3, 99)
         i = iter(t)
         assert i.next() == 5
         assert i.next() == 3
@@ -263,7 +263,7 @@
         raises(StopIteration, i.next)
 
     def test_contains(self):
-        t = (5,3,99)
+        t = (5, 3, 99)
         assert 5 in t
         assert 99 in t
         assert not 11 in t
@@ -271,35 +271,35 @@
 
     def test_add(self):
         t0 = ()
-        t1 = (5,3,99)
+        t1 = (5, 3, 99)
         assert t0 + t0 == t0
         assert t1 + t0 == t1
-        assert t1 + t1 == (5,3,99,5,3,99)
+        assert t1 + t1 == (5, 3, 99, 5, 3, 99)
 
     def test_mul(self):
         assert () * 10 == ()
-        assert (5,) * 3 == (5,5,5)
-        assert (5,2) * 2 == (5,2,5,2)
+        assert (5,) * 3 == (5, 5, 5)
+        assert (5, 2) * 2 == (5, 2, 5, 2)
 
     def test_mul_identity(self):
-        t = (1,2,3)
+        t = (1, 2, 3)
         assert (t * 1) is t
 
     def test_mul_subtype(self):
         class T(tuple): pass
-        t = T([1,2,3])
+        t = T([1, 2, 3])
         assert (t * 1) is not t
         assert (t * 1) == t
 
     def test_getslice_2(self):
-        assert (5,2,3)[1:2] == (2,)
+        assert (5, 2, 3)[1:2] == (2,)
 
     def test_eq(self):
         t0 = ()
-        t1 = (5,3,99)
-        t2 = (5,3,99)
-        t3 = (5,3,99,-1)
-        t4 = (5,3,9,1)
+        t1 = (5, 3, 99)
+        t2 = (5, 3, 99)
+        t3 = (5, 3, 99, -1)
+        t4 = (5, 3, 9, 1)
         assert not t0 == t1
         assert t0 != t1
         assert t1 == t2
@@ -321,15 +321,15 @@
         # check that hash behaves as in 2.4 for at least 31 bits
         assert hash(()) & 0x7fffffff == 0x35d373
         assert hash((12,)) & 0x7fffffff == 0x1cca0557
-        assert hash((12,34)) & 0x7fffffff == 0x153e2a41
+        assert hash((12, 34)) & 0x7fffffff == 0x153e2a41
 
     def test_getnewargs(self):
-        assert  () .__getnewargs__() == ((),)
+        assert () .__getnewargs__() == ((),)
 
     def test_repr(self):
         assert repr((1,)) == '(1,)'
         assert repr(()) == '()'
-        assert repr((1,2,3)) == '(1, 2, 3)'
+        assert repr((1, 2, 3)) == '(1, 2, 3)'
 
     def test_getslice(self):
         assert ('a', 'b', 'c').__getslice__(-17, 2) == ('a', 'b')


More information about the pypy-commit mailing list