[pypy-commit] pypy default: minor cleanup

pjenvey noreply at buildbot.pypy.org
Thu May 23 01:41:45 CEST 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: 
Changeset: r64498:91b978e64619
Date: 2013-05-22 16:40 -0700
http://bitbucket.org/pypy/pypy/changeset/91b978e64619/

Log:	minor cleanup

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1,5 +1,14 @@
+"""The builtin list implementation
+
+Lists optimize their storage by holding certain primitive datatypes in
+unwrapped form. For more information:
+
+http://morepypy.blogspot.com/2011/10/more-compact-lists-with-list-strategies.html
+
+"""
+
 import operator
-from sys import maxint
+import sys
 
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -18,11 +27,11 @@
 from pypy.objspace.std.stringobject import W_StringObject
 from pypy.objspace.std.tupleobject import W_AbstractTupleObject
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
-from pypy.objspace.std.util import negate, get_positive_index
-from rpython.rlib import rerased, jit, debug
+from pypy.objspace.std.util import get_positive_index, negate
+from rpython.rlib import debug, jit, rerased
 from rpython.rlib.listsort import make_timsort_class
-from rpython.rlib.objectmodel import (instantiate, newlist_hint, specialize,
-    resizelist_hint)
+from rpython.rlib.objectmodel import (
+    instantiate, newlist_hint, resizelist_hint, specialize)
 from rpython.tool.sourcetools import func_with_new_name
 
 __all__ = ['W_ListObject', 'make_range_list', 'make_empty_list_with_size']
@@ -130,26 +139,26 @@
 
 
 class W_ListObject(W_Root):
-    def __init__(w_self, space, wrappeditems, sizehint=-1):
+
+    def __init__(self, space, wrappeditems, sizehint=-1):
         assert isinstance(wrappeditems, list)
-        w_self.space = space
+        self.space = space
         if space.config.objspace.std.withliststrategies:
-            w_self.strategy = get_strategy_from_list_objects(space,
-                                                             wrappeditems,
-                                                             sizehint)
+            self.strategy = get_strategy_from_list_objects(space, wrappeditems,
+                                                           sizehint)
         else:
-            w_self.strategy = space.fromcache(ObjectListStrategy)
-        w_self.init_from_list_w(wrappeditems)
+            self.strategy = space.fromcache(ObjectListStrategy)
+        self.init_from_list_w(wrappeditems)
 
     @staticmethod
     def from_storage_and_strategy(space, storage, strategy):
-        w_self = instantiate(W_ListObject)
-        w_self.space = space
-        w_self.strategy = strategy
-        w_self.lstorage = storage
+        self = instantiate(W_ListObject)
+        self.space = space
+        self.strategy = strategy
+        self.lstorage = storage
         if not space.config.objspace.std.withliststrategies:
-            w_self.switch_to_object_strategy()
-        return w_self
+            self.switch_to_object_strategy()
+        return self
 
     @staticmethod
     def newlist_str(space, list_s):
@@ -157,10 +166,10 @@
         storage = strategy.erase(list_s)
         return W_ListObject.from_storage_and_strategy(space, storage, strategy)
 
-    def __repr__(w_self):
+    def __repr__(self):
         """ representation for debugging purposes """
-        return "%s(%s, %s)" % (w_self.__class__.__name__, w_self.strategy,
-                               w_self.lstorage._x)
+        return "%s(%s, %s)" % (self.__class__.__name__, self.strategy,
+                               self.lstorage._x)
 
     def unwrap(w_list, space):
         # for tests only!
@@ -216,7 +225,7 @@
         strategy and storage according to the other W_List"""
         self.strategy.copy_into(self, other)
 
-    def find(self, w_item, start=0, end=maxint):
+    def find(self, w_item, start=0, end=sys.maxint):
         """Find w_item in list[start:end]. If not found, raise ValueError"""
         return self.strategy.find(self, w_item, start, end)
 
@@ -590,14 +599,14 @@
         'L.remove(value) -- remove first occurrence of value'
         # needs to be safe against eq_w() mutating the w_list behind our back
         try:
-            i = self.find(w_value, 0, maxint)
+            i = self.find(w_value, 0, sys.maxint)
         except ValueError:
             raise OperationError(space.w_ValueError,
                                  space.wrap("list.remove(x): x not in list"))
         if i < self.length():  # otherwise list was mutated
             self.pop(i)
 
-    @unwrap_spec(w_start=WrappedDefault(0), w_stop=WrappedDefault(maxint))
+    @unwrap_spec(w_start=WrappedDefault(0), w_stop=WrappedDefault(sys.maxint))
     def descr_index(self, space, w_value, w_start, w_stop):
         '''L.index(value, [start, [stop]]) -> integer -- return
         first index of value'''
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -18,18 +18,18 @@
 class W_BaseSetObject(W_Root):
     typedef = None
 
-    def __init__(w_self, space, w_iterable=None):
+    def __init__(self, space, w_iterable=None):
         """Initialize the set by taking ownership of 'setdata'."""
-        w_self.space = space
-        set_strategy_and_setdata(space, w_self, w_iterable)
+        self.space = space
+        set_strategy_and_setdata(space, self, w_iterable)
 
-    def __repr__(w_self):
+    def __repr__(self):
         """representation for debugging purposes"""
-        reprlist = [repr(w_item) for w_item in w_self.getkeys()]
-        return "<%s(%s)>" % (w_self.__class__.__name__, ', '.join(reprlist))
+        reprlist = [repr(w_item) for w_item in self.getkeys()]
+        return "<%s(%s)>" % (self.__class__.__name__, ', '.join(reprlist))
 
-    def from_storage_and_strategy(w_self, storage, strategy):
-        obj = w_self._newobj(w_self.space, None)
+    def from_storage_and_strategy(self, storage, strategy):
+        obj = self._newobj(self.space, None)
         assert isinstance(obj, W_BaseSetObject)
         obj.strategy = strategy
         obj.sstorage = storage
@@ -501,11 +501,11 @@
 
 
 class W_SetObject(W_BaseSetObject):
-    def _newobj(w_self, space, w_iterable):
+    def _newobj(self, space, w_iterable):
         """Make a new set by taking ownership of 'w_iterable'."""
-        if type(w_self) is W_SetObject:
+        if type(self) is W_SetObject:
             return W_SetObject(space, w_iterable)
-        w_type = space.type(w_self)
+        w_type = space.type(self)
         w_obj = space.allocate_instance(W_SetObject, w_type)
         W_SetObject.__init__(w_obj, space, w_iterable)
         return w_obj
@@ -577,11 +577,11 @@
 class W_FrozensetObject(W_BaseSetObject):
     hash = 0
 
-    def _newobj(w_self, space, w_iterable):
+    def _newobj(self, space, w_iterable):
         """Make a new frozenset by taking ownership of 'w_iterable'."""
-        if type(w_self) is W_FrozensetObject:
+        if type(self) is W_FrozensetObject:
             return W_FrozensetObject(space, w_iterable)
-        w_type = space.type(w_self)
+        w_type = space.type(self)
         w_obj = space.allocate_instance(W_FrozensetObject, w_type)
         W_FrozensetObject.__init__(w_obj, space, w_iterable)
         return w_obj
@@ -1439,9 +1439,9 @@
 
 class W_SetIterObject(W_Root):
 
-    def __init__(w_self, space, iterimplementation):
-        w_self.space = space
-        w_self.iterimplementation = iterimplementation
+    def __init__(self, space, iterimplementation):
+        self.space = space
+        self.iterimplementation = iterimplementation
 
     def descr_length_hint(self, space):
         return space.wrap(self.iterimplementation.length())
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
@@ -14,13 +14,13 @@
 def make_specialised_class(typetuple):
     assert type(typetuple) == tuple
 
-    nValues = len(typetuple)
-    iter_n = unrolling_iterable(range(nValues))
+    typelen = len(typetuple)
+    iter_n = unrolling_iterable(range(typelen))
 
     class cls(W_AbstractTupleObject):
         def __init__(self, space, *values_w):
             self.space = space
-            assert len(values_w) == nValues
+            assert len(values_w) == typelen
             for i in iter_n:
                 w_obj = values_w[i]
                 val_type = typetuple[i]
@@ -37,10 +37,10 @@
                 setattr(self, 'value%s' % i, unwrapped)
 
         def length(self):
-            return nValues
+            return typelen
 
         def tolist(self):
-            list_w = [None] * nValues
+            list_w = [None] * typelen
             for i in iter_n:
                 value = getattr(self, 'value%s' % i)
                 if typetuple[i] != object:
@@ -54,7 +54,7 @@
         def descr_hash(self, space):
             mult = 1000003
             x = 0x345678
-            z = nValues
+            z = typelen
             for i in iter_n:
                 value = getattr(self, 'value%s' % i)
                 if typetuple[i] == object:
@@ -76,7 +76,7 @@
             if not isinstance(w_other, W_AbstractTupleObject):
                 return space.w_NotImplemented
             if not isinstance(w_other, cls):
-                if nValues != w_other.length():
+                if typelen != w_other.length():
                     return space.w_False
                 for i in iter_n:
                     myval = getattr(self, 'value%s' % i)
@@ -102,7 +102,7 @@
 
         def getitem(self, space, index):
             if index < 0:
-                index += nValues
+                index += typelen
             for i in iter_n:
                 if index == i:
                     value = getattr(self, 'value%s' % i)
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -1,8 +1,11 @@
+"""The builtin tuple implementation"""
+
 import sys
-from pypy.interpreter import gateway
+
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import interp2app, interpindirect2app
+from pypy.interpreter.gateway import (
+    WrappedDefault, interp2app, interpindirect2app, unwrap_spec)
 from pypy.objspace.std import slicetype
 from pypy.objspace.std.inttype import wrapint
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
@@ -177,8 +180,7 @@
                 count += 1
         return space.wrap(count)
 
-    @gateway.unwrap_spec(w_start=gateway.WrappedDefault(0),
-                         w_stop=gateway.WrappedDefault(sys.maxint))
+    @unwrap_spec(w_start=WrappedDefault(0), w_stop=WrappedDefault(sys.maxint))
     @jit.look_inside_iff(lambda self, _1, _2, _3, _4: _unroll_condition(self))
     def descr_index(self, space, w_obj, w_start, w_stop):
         """index(obj, [start, [stop]]) -> first index that obj appears in the


More information about the pypy-commit mailing list