[pypy-svn] pypy improve-unwrap_spec: More progress

amauryfa commits-noreply at bitbucket.org
Wed Feb 16 19:19:13 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42051:0f2ff1b4d199
Date: 2011-02-16 11:15 +0100
http://bitbucket.org/pypy/pypy/changeset/0f2ff1b4d199/

Log:	More progress

diff --git a/pypy/module/_demo/demo.py b/pypy/module/_demo/demo.py
--- a/pypy/module/_demo/demo.py
+++ b/pypy/module/_demo/demo.py
@@ -18,6 +18,7 @@
     return space.getattr(w_module, space.wrap(name))
 
 
+ at unwrap_spec(repetitions=int)
 def measuretime(space, repetitions, w_callable):
     if repetitions <= 0:
         w_DemoError = get(space, 'DemoError')
@@ -28,8 +29,8 @@
         space.call_function(w_callable)
     endtime = time(0)
     return space.wrap(endtime - starttime)
-measuretime.unwrap_spec = [ObjSpace, int, W_Root]
 
+ at unwrap_spec(n=int)
 def sieve(space, n):
     lst = range(2, n + 1)
     head = 0
@@ -46,7 +47,6 @@
                 newlst.append(element)
         lst = newlst
         head += 1
-sieve.unwrap_spec = [ObjSpace, int]
  
 class W_MyType(Wrappable):
     def __init__(self, space, x=1):
@@ -64,11 +64,11 @@
     def fset_x(space, self, w_value):
         self.x = space.int_w(w_value)
 
+ at unwrap_spec(x=int)
 def mytype_new(space, w_subtype, x):
     if x == 3:
         return space.wrap(MySubType(space, x))
     return space.wrap(W_MyType(space, x))
-mytype_new.unwrap_spec = [ObjSpace, W_Root, int]
 
 getset_x = GetSetProperty(W_MyType.fget_x, W_MyType.fset_x, cls=W_MyType)
 

diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.objspace.std.typeobject import MethodCache
 from pypy.objspace.std.mapdict import IndexCache
@@ -22,6 +22,7 @@
     import pdb
     pdb.set_trace()
 
+ at unwrap_spec(name=str)
 def method_cache_counter(space, name):
     """Return a tuple (method_cache_hits, method_cache_misses) for calls to
     methods with the name."""
@@ -29,7 +30,6 @@
     cache = space.fromcache(MethodCache)
     return space.newtuple([space.newint(cache.hits.get(name, 0)),
                            space.newint(cache.misses.get(name, 0))])
-method_cache_counter.unwrap_spec = [ObjSpace, str]
 
 def reset_method_cache_counter(space):
     """Reset the method cache counter to zero for all method names."""
@@ -42,6 +42,7 @@
         cache.misses = {}
         cache.hits = {}
 
+ at unwrap_spec(name=str)
 def mapdict_cache_counter(space, name):
     """Return a tuple (index_cache_hits, index_cache_misses) for lookups
     in the mapdict cache with the given attribute name."""
@@ -50,7 +51,6 @@
     cache = space.fromcache(IndexCache)
     return space.newtuple([space.newint(cache.hits.get(name, 0)),
                            space.newint(cache.misses.get(name, 0))])
-mapdict_cache_counter.unwrap_spec = [ObjSpace, str]
 
 def builtinify(space, w_func):
     from pypy.interpreter.function import Function, BuiltinFunction

diff --git a/pypy/module/__pypy__/interp_identitydict.py b/pypy/module/__pypy__/interp_identitydict.py
--- a/pypy/module/__pypy__/interp_identitydict.py
+++ b/pypy/module/__pypy__/interp_identitydict.py
@@ -1,59 +1,47 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped, interp2app
-from pypy.interpreter.gateway import Arguments, unwrap_spec
+from pypy.interpreter.gateway import NoneNotWrapped, interp2app, unwrap_spec
 from pypy.interpreter.baseobjspace import Wrappable
 
 class W_IdentityDict(Wrappable):
     def __init__(self, space):
         self.dict = {}
-    __init__.unwrap_spec = ['self', ObjSpace]
 
-    @unwrap_spec(ObjSpace, W_Root)
     def descr_new(space, w_subtype):
         self = space.allocate_instance(W_IdentityDict, w_subtype)
         W_IdentityDict.__init__(self, space)
         return space.wrap(self)
 
-    @unwrap_spec('self', ObjSpace)
     def descr_len(self, space):
         return space.wrap(len(self.dict))
 
-    @unwrap_spec('self', ObjSpace, W_Root)
     def descr_contains(self, space, w_key):
         return space.wrap(w_key in self.dict)
 
-    @unwrap_spec('self', ObjSpace, W_Root, W_Root)
     def descr_setitem(self, space, w_key, w_value):
         self.dict[w_key] = w_value
 
-    @unwrap_spec('self', ObjSpace, W_Root)
     def descr_getitem(self, space, w_key):
         try:
             return self.dict[w_key]
         except KeyError:
             raise OperationError(space.w_KeyError, w_key)
 
-    @unwrap_spec('self', ObjSpace, W_Root)
     def descr_delitem(self, space, w_key):
         try:
             del self.dict[w_key]
         except KeyError:
             raise OperationError(space.w_KeyError, w_key)
 
-    @unwrap_spec('self', ObjSpace, W_Root, W_Root)
     def get(self, space, w_key, w_default=None):
         return self.dict.get(w_key, w_default)
 
-    @unwrap_spec('self', ObjSpace)
     def keys(self, space):
         return space.newlist(self.dict.keys())
 
-    @unwrap_spec('self', ObjSpace)
     def values(self, space):
         return space.newlist(self.dict.values())
 
-    @unwrap_spec('self', ObjSpace)
     def clear(self, space):
         self.dict.clear()
 

diff --git a/pypy/module/__pypy__/interp_debug.py b/pypy/module/__pypy__/interp_debug.py
--- a/pypy/module/__pypy__/interp_debug.py
+++ b/pypy/module/__pypy__/interp_debug.py
@@ -1,22 +1,22 @@
-from pypy.interpreter.gateway import interp2app, NoneNotWrapped, unwrap_spec, ObjSpace
+from pypy.interpreter.gateway import interp2app, NoneNotWrapped, unwrap_spec
 from pypy.interpreter.error import OperationError
 from pypy.rlib import debug
 
- at unwrap_spec(ObjSpace, str)
+ at unwrap_spec(category=str)
 def debug_start(space, category):
     debug.debug_start(category)
 
- at unwrap_spec(ObjSpace, 'args_w')
+ at unwrap_spec(args_w='args_w')
 def debug_print(space, args_w):
     parts = [space.str_w(space.str(w_item)) for w_item in args_w]
     debug.debug_print(' '.join(parts))
 
- at unwrap_spec(ObjSpace, str)
+ at unwrap_spec(category=str)
 def debug_stop(space, category):
     debug.debug_stop(category)
 
 
- at unwrap_spec(ObjSpace, str, 'args_w')
+ at unwrap_spec(category=str, args_w='args_w')
 def debug_print_once(space, category, args_w):
     debug_start(space, category)
     debug_print(space, args_w)

diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -1,7 +1,5 @@
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import ObjSpace, NoneNotWrapped, interp2app
-from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import NoneNotWrapped, interp2app, unwrap_spec
 from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
 from pypy.rlib.objectmodel import we_are_translated
 
@@ -89,9 +87,9 @@
         raise OperationError(
             space.w_TypeError,
             space.wrap("argument must be callable"))
-register_codec.unwrap_spec = [ObjSpace, W_Root]
 
 
+ at unwrap_spec(encoding=str)
 def lookup_codec(space, encoding):
     """lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)
     Looks up a codec tuple in the Python codec registry and returns
@@ -130,7 +128,6 @@
     raise operationerrfmt(
         space.w_LookupError,
         "unknown encoding: %s", encoding)
-lookup_codec.unwrap_spec = [ObjSpace, str]
 
 # ____________________________________________________________
 # Register standard error handlers
@@ -255,6 +252,7 @@
         state.codec_error_registry[error] = space.wrap(interp2app(globals()[name]))
 
 
+ at unwrap_spec(errors=str)
 def lookup_error(space, errors):
     """lookup_error(errors) -> handler
 
@@ -270,9 +268,9 @@
             space.w_LookupError,
             "unknown error handler name %s", errors)
     return w_err_handler
-lookup_error.unwrap_spec = [ObjSpace, str]
 
 
+ at unwrap_spec(errors=str)
 def encode(space, w_obj, w_encoding=NoneNotWrapped, errors='strict'):
     """encode(obj, [encoding[,errors]]) -> object
 
@@ -290,12 +288,12 @@
     w_encoder = space.getitem(lookup_codec(space, encoding), space.wrap(0))
     w_res = space.call_function(w_encoder, w_obj, space.wrap(errors))
     return space.getitem(w_res, space.wrap(0))
-encode.unwrap_spec = [ObjSpace, W_Root, W_Root, str]
 
+ at unwrap_spec(s='bufferstr', errors='str_or_None')
 def buffer_encode(space, s, errors='strict'):
     return space.newtuple([space.wrap(s), space.wrap(len(s))])
-buffer_encode.unwrap_spec = [ObjSpace, 'bufferstr', 'str_or_None']
 
+ at unwrap_spec(errors=str)
 def decode(space, w_obj, w_encoding=NoneNotWrapped, errors='strict'):
     """decode(obj, [encoding[,errors]]) -> object
 
@@ -321,8 +319,8 @@
         return space.getitem(w_res, space.wrap(0))
     else:
         assert 0, "XXX, what to do here?"
-decode.unwrap_spec = [ObjSpace, W_Root, W_Root, str]
 
+ at unwrap_spec(errors=str)
 def register_error(space, errors, w_handler):
     """register_error(errors, handler)
 
@@ -339,7 +337,6 @@
         raise OperationError(
             space.w_TypeError,
             space.wrap("handler must be callable"))
-register_error.unwrap_spec = [ObjSpace, str, W_Root]
 
 # ____________________________________________________________
 # delegation to runicode
@@ -381,6 +378,7 @@
 def make_encoder_wrapper(name):
     rname = "unicode_encode_%s" % (name.replace("_encode", ""), )
     assert hasattr(runicode, rname)
+    @unwrap_spec(uni=unicode, errors='str_or_None')
     def wrap_encoder(space, uni, errors="strict"):
         if errors is None:
             errors = 'strict'
@@ -389,12 +387,12 @@
         result = func(uni, len(uni), errors, state.encode_error_handler)
         return space.newtuple([space.wrap(result), space.wrap(len(uni))])
     wrap_encoder.func_name = rname
-    wrap_encoder.unwrap_spec = [ObjSpace, unicode, 'str_or_None']
     globals()[name] = wrap_encoder
 
 def make_decoder_wrapper(name):
     rname = "str_decode_%s" % (name.replace("_decode", ""), )
     assert hasattr(runicode, rname)
+    @unwrap_spec(string='bufferstr', errors='str_or_None')
     def wrap_decoder(space, string, errors="strict", w_final=False):
         if errors is None:
             errors = 'strict'
@@ -405,7 +403,6 @@
                                 final, state.decode_error_handler)
         return space.newtuple([space.wrap(result), space.wrap(consumed)])
     wrap_decoder.func_name = rname
-    wrap_decoder.unwrap_spec = [ObjSpace, 'bufferstr', 'str_or_None', W_Root]
     globals()[name] = wrap_decoder
 
 for encoders in [
@@ -444,6 +441,7 @@
     make_encoder_wrapper('mbcs_encode')
     make_decoder_wrapper('mbcs_decode')
 
+ at unwrap_spec(data=str, errors='str_or_None', byteorder=int)
 def utf_16_ex_decode(space, data, errors='strict', byteorder=0, w_final=False):
     if errors is None:
         errors = 'strict'
@@ -462,8 +460,8 @@
         data, len(data), errors, final, state.decode_error_handler, byteorder)
     return space.newtuple([space.wrap(res), space.wrap(consumed),
                            space.wrap(byteorder)])
-utf_16_ex_decode.unwrap_spec = [ObjSpace, str, 'str_or_None', int, W_Root]
 
+ at unwrap_spec(data=str, errors='str_or_None', byteorder=int)
 def utf_32_ex_decode(space, data, errors='strict', byteorder=0, w_final=False):
     final = space.is_true(w_final)
     state = space.fromcache(CodecState)
@@ -480,7 +478,6 @@
         data, len(data), errors, final, state.decode_error_handler, byteorder)
     return space.newtuple([space.wrap(res), space.wrap(consumed),
                            space.wrap(byteorder)])
-utf_32_ex_decode.unwrap_spec = [ObjSpace, str, str, int, W_Root]
 
 # ____________________________________________________________
 # Charmap
@@ -583,7 +580,7 @@
         raise OperationError(space.w_TypeError, space.wrap("invalid mapping"))
 
 
- at unwrap_spec(ObjSpace, str, 'str_or_None', W_Root)
+ at unwrap_spec(string=str, errors='str_or_None')
 def charmap_decode(space, string, errors="strict", w_mapping=None):
     if errors is None:
         errors = 'strict'
@@ -602,7 +599,7 @@
         final, state.decode_error_handler, mapping)
     return space.newtuple([space.wrap(result), space.wrap(consumed)])
 
- at unwrap_spec(ObjSpace, unicode, 'str_or_None', W_Root)
+ at unwrap_spec(uni=unicode, errors='str_or_None')
 def charmap_encode(space, uni, errors="strict", w_mapping=None):
     if errors is None:
         errors = 'strict'
@@ -618,7 +615,7 @@
     return space.newtuple([space.wrap(result), space.wrap(len(uni))])
 
 
- at unwrap_spec(ObjSpace, unicode)
+ at unwrap_spec(chars=unicode)
 def charmap_build(space, chars):
     # XXX CPython sometimes uses a three-level trie
     w_charmap = space.newdict()
@@ -645,7 +642,7 @@
             return -1
         return space.int_w(w_code)
 
- at unwrap_spec(ObjSpace, 'bufferstr', 'str_or_None', W_Root)
+ at unwrap_spec(string='bufferstr', errors='str_or_None')
 def unicode_escape_decode(space, string, errors="strict", w_final=False):
     if errors is None:
         errors = 'strict'
@@ -665,7 +662,7 @@
 # ____________________________________________________________
 # Unicode-internal
 
- at unwrap_spec(ObjSpace, W_Root, 'str_or_None')
+ at unwrap_spec(errors='str_or_None')
 def unicode_internal_decode(space, w_string, errors="strict"):
     if errors is None:
         errors = 'strict'
@@ -689,13 +686,13 @@
 # support for the "string escape" codec
 # This is a bytes-to bytes transformation
 
- at unwrap_spec(ObjSpace, W_Root, 'str_or_None')
+ at unwrap_spec(errors='str_or_None')
 def escape_encode(space, w_string, errors='strict'):
     w_repr = space.repr(w_string)
     w_result = space.getslice(w_repr, space.wrap(1), space.wrap(-1))
     return space.newtuple([w_result, space.len(w_string)])
 
- at unwrap_spec(ObjSpace, str, 'str_or_None')
+ at unwrap_spec(data=str, errors='str_or_None')
 def escape_decode(space, data, errors='strict'):
     from pypy.interpreter.pyparser.parsestring import PyString_DecodeEscape
     result = PyString_DecodeEscape(space, data, None)

diff --git a/pypy/module/_bisect/interp_bisect.py b/pypy/module/_bisect/interp_bisect.py
--- a/pypy/module/_bisect/interp_bisect.py
+++ b/pypy/module/_bisect/interp_bisect.py
@@ -1,7 +1,8 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace, W_Root
+from pypy.interpreter.gateway import unwrap_spec
 
 
+ at unwrap_spec(lo=int, hi=int)
 def bisect_left(space, w_a, w_x, lo=0, hi=-1):
     """Return the index where to insert item x in list a, assuming a is sorted.
 
@@ -24,9 +25,9 @@
         else:
             hi = mid
     return space.wrap(lo)
-bisect_left.unwrap_spec = [ObjSpace, W_Root, W_Root, int, int]
 
 
+ at unwrap_spec(lo=int, hi=int)
 def bisect_right(space, w_a, w_x, lo=0, hi=-1):
     """Return the index where to insert item x in list a, assuming a is sorted.
 
@@ -49,4 +50,3 @@
         else:
             lo = mid + 1
     return space.wrap(lo)
-bisect_right.unwrap_spec = [ObjSpace, W_Root, W_Root, int, int]

diff --git a/pypy/module/__pypy__/bytebuffer.py b/pypy/module/__pypy__/bytebuffer.py
--- a/pypy/module/__pypy__/bytebuffer.py
+++ b/pypy/module/__pypy__/bytebuffer.py
@@ -3,7 +3,7 @@
 #
 
 from pypy.interpreter.buffer import RWBuffer
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 
 
 class ByteBuffer(RWBuffer):
@@ -21,6 +21,6 @@
         self.data[index] = char
 
 
+ at unwrap_spec(length=int)
 def bytebuffer(space, length):
     return space.wrap(ByteBuffer(length))
-bytebuffer.unwrap_spec = [ObjSpace, int]


More information about the Pypy-commit mailing list