[pypy-commit] pypy default: cleanup

pjenvey noreply at buildbot.pypy.org
Thu Feb 13 21:00:26 CET 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: 
Changeset: r69134:75ef172c843b
Date: 2014-02-10 18:07 -0800
http://bitbucket.org/pypy/pypy/changeset/75ef172c843b/

Log:	cleanup

diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -1,3 +1,10 @@
+"""The builtin dict implementation"""
+
+from rpython.rlib import jit, rerased
+from rpython.rlib.debug import mark_dict_non_null
+from rpython.rlib.objectmodel import newlist_hint, r_dict, specialize
+from rpython.tool.sourcetools import func_renamer, func_with_new_name
+
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import (
@@ -7,18 +14,10 @@
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.util import negate
 
-from rpython.rlib import jit, rerased
-from rpython.rlib.debug import mark_dict_non_null
-from rpython.rlib.objectmodel import newlist_hint, r_dict, specialize
-from rpython.tool.sourcetools import func_renamer, func_with_new_name
-
 
 UNROLL_CUTOFF = 5
 
 
-def _is_str(space, w_key):
-    return space.is_w(space.type(w_key), space.w_str)
-
 def _never_equal_to_string(space, w_lookup_type):
     """Handles the case of a non string key lookup.
     Types that have a sane hash/eq function should allow us to return True
@@ -29,8 +28,8 @@
     return (space.is_w(w_lookup_type, space.w_NoneType) or
             space.is_w(w_lookup_type, space.w_int) or
             space.is_w(w_lookup_type, space.w_bool) or
-            space.is_w(w_lookup_type, space.w_float)
-            )
+            space.is_w(w_lookup_type, space.w_float))
+
 
 @specialize.call_location()
 def w_dict_unrolling_heuristic(w_dct):
@@ -69,19 +68,18 @@
             w_type = space.w_dict
 
         storage = strategy.get_empty_storage()
-        w_self = space.allocate_instance(W_DictMultiObject, w_type)
-        W_DictMultiObject.__init__(w_self, space, strategy, storage)
-        return w_self
+        w_obj = space.allocate_instance(W_DictMultiObject, w_type)
+        W_DictMultiObject.__init__(w_obj, space, strategy, storage)
+        return w_obj
 
     def __init__(self, space, strategy, storage):
         self.space = space
         self.strategy = strategy
         self.dstorage = storage
 
-    def __repr__(w_self):
+    def __repr__(self):
         """representation for debugging purposes"""
-        #print('XXXXXXX', w_self.dstorage)
-        return "%s(%s)" % (w_self.__class__.__name__, w_self.strategy)
+        return "%s(%s)" % (self.__class__.__name__, self.strategy)
 
     def unwrap(w_dict, space):
         result = {}
@@ -98,9 +96,9 @@
                 return space.get_and_call_function(w_missing, w_dict, w_key)
         return None
 
-    def initialize_content(w_self, list_pairs_w):
+    def initialize_content(self, list_pairs_w):
         for w_k, w_v in list_pairs_w:
-            w_self.setitem(w_k, w_v)
+            self.setitem(w_k, w_v)
 
     def setitem_str(self, key, w_value):
         self.strategy.setitem_str(self, key, w_value)
@@ -115,7 +113,8 @@
         if w_fill is None:
             w_fill = space.w_None
         if space.is_w(w_type, space.w_dict):
-            w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type)
+            w_dict = W_DictMultiObject.allocate_and_init_instance(space,
+                                                                  w_type)
 
             byteslist = space.listview_bytes(w_keys)
             if byteslist is not None:
@@ -312,8 +311,7 @@
         try:
             w_key, w_value = self.popitem()
         except KeyError:
-            raise OperationError(space.w_KeyError,
-                                 space.wrap("popitem(): dictionary is empty"))
+            raise oefmt(space.w_KeyError, "popitem(): dictionary is empty")
         return space.newtuple([w_key, w_value])
 
     @unwrap_spec(w_default=WrappedDefault(None))
@@ -597,6 +595,7 @@
     def getiterkeys(self, w_dict):
         return iter([None])
     getitervalues = getiterkeys
+
     def getiteritems(self, w_dict):
         return iter([(None, None)])
 
@@ -615,8 +614,8 @@
         space = self.space
         if self.len != self.dictimplementation.length():
             self.len = -1   # Make this error state sticky
-            msg = "dictionary changed size during iteration"
-            raise OperationError(space.w_RuntimeError, space.wrap(msg))
+            raise oefmt(space.w_RuntimeError,
+                        "dictionary changed size during iteration")
 
         # look for the next entry
         if self.pos < self.len:
@@ -635,14 +634,15 @@
                 w_value = self.dictimplementation.getitem(w_key)
                 if w_value is None:
                     self.len = -1   # Make this error state sticky
-                    msg = "dictionary changed during iteration"
-                    raise OperationError(space.w_RuntimeError, space.wrap(msg))
+                    raise oefmt(space.w_RuntimeError,
+                                "dictionary changed during iteration")
                 return (w_key, w_value)
         # no more entries
         self.dictimplementation = None
         return EMPTY
     return func_with_new_name(next, 'next_' + TP)
 
+
 class BaseIteratorImplementation(object):
     def __init__(self, space, strategy, implementation):
         self.space = space
@@ -665,13 +665,14 @@
 class BaseItemIterator(BaseIteratorImplementation):
     next_item = _new_next('item')
 
+
 def create_iterator_classes(dictimpl, override_next_item=None):
     if not hasattr(dictimpl, 'wrapkey'):
-        wrapkey = lambda space, key : key
+        wrapkey = lambda space, key: key
     else:
         wrapkey = dictimpl.wrapkey.im_func
     if not hasattr(dictimpl, 'wrapvalue'):
-        wrapvalue = lambda space, key : key
+        wrapvalue = lambda space, key: key
     else:
         wrapvalue = dictimpl.wrapvalue.im_func
 
@@ -800,7 +801,8 @@
             return w_dict.getitem(w_key)
 
     def w_keys(self, w_dict):
-        l = [self.wrap(key) for key in self.unerase(w_dict.dstorage).iterkeys()]
+        l = [self.wrap(key)
+             for key in self.unerase(w_dict.dstorage).iterkeys()]
         return self.space.newlist(l)
 
     def values(self, w_dict):
@@ -1036,7 +1038,8 @@
     def wrapkey(space, key):
         return space.wrap(key)
 
-    # XXX there is no space.newlist_int yet to implement w_keys more efficiently
+    # XXX there is no space.newlist_int yet to implement w_keys more
+    # efficiently
 
 create_iterator_classes(IntDictStrategy)
 
@@ -1071,8 +1074,7 @@
     for w_pair in data_w:
         pair = space.fixedview(w_pair)
         if len(pair) != 2:
-            raise OperationError(space.w_ValueError,
-                         space.wrap("sequence of pairs expected"))
+            raise oefmt(space.w_ValueError, "sequence of pairs expected")
         w_key, w_value = pair
         w_dict.setitem(w_key, w_value)
 
@@ -1128,9 +1130,9 @@
 
     ignore_for_isinstance_cache = True
 
-    def __init__(w_self, space, iteratorimplementation):
-        w_self.space = space
-        w_self.iteratorimplementation = iteratorimplementation
+    def __init__(self, space, iteratorimplementation):
+        self.space = space
+        self.iteratorimplementation = iteratorimplementation
 
     def descr_iter(self, space):
         return self
@@ -1158,9 +1160,8 @@
         new_inst = mod.get('dictiter_surrogate_new')
         w_typeobj = space.type(self)
 
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("can't pickle dictionary-keyiterator objects"))
+        raise oefmt(space.w_TypeError,
+                    "can't pickle dictionary-keyiterator objects")
         # XXXXXX get that working again
 
         # we cannot call __init__ since we don't have the original dict
@@ -1174,8 +1175,8 @@
             w_clone = space.allocate_instance(W_DictMultiIterItemsObject,
                                               w_typeobj)
         else:
-            msg = "unsupported dictiter type '%s' during pickling" % (self,)
-            raise OperationError(space.w_TypeError, space.wrap(msg))
+            raise oefmt(space.w_TypeError,
+                        "unsupported dictiter type '%R' during pickling", self)
         w_clone.space = space
         w_clone.content = self.content
         w_clone.len = self.len
@@ -1244,8 +1245,8 @@
 # Views
 
 class W_DictViewObject(W_Root):
-    def __init__(w_self, space, w_dict):
-        w_self.w_dict = w_dict
+    def __init__(self, space, w_dict):
+        self.w_dict = w_dict
 
     def descr_repr(self, space):
         w_seq = space.call_function(space.w_list, self)


More information about the pypy-commit mailing list