Commits

Armin Rigo  committed cccfbcc

(fijal, arigo)

in-progress: refactoring the NoneNotWrapped away, yay

  • Participants
  • Parent commits 5543bcb
  • Branches kill-someobject

Comments (0)

Files changed (17)

File pypy/interpreter/gateway.py

 
 import py
 
-NoneNotWrapped = object()
-
 from pypy.interpreter import eval
 from pypy.interpreter.argument import Arguments, Signature
 from pypy.interpreter.baseobjspace import (W_Root, ObjSpace, Wrappable,
         self.miniglobals[name] = obj
         return name
 
+
+def is_none(space, w_obj):
+    return w_obj is None or space.is_w(w_obj, space.w_None)
+
 #________________________________________________________________
 
 
     # When a BuiltinCode is stored in a Function object,
     # you get the functionality of CPython's built-in function type.
 
-    NOT_RPYTHON_ATTRIBUTES = ['_bltin', '_unwrap_spec']
-
     def __init__(self, func, unwrap_spec=None, self_type=None, descrmismatch=None):
         "NOT_RPYTHON"
         # 'implfunc' is the interpreter-level function.
 class interp2app(Wrappable):
     """Build a gateway that calls 'f' at interp-level."""
 
-    # NOTICE interp2app defaults are stored and passed as
-    # wrapped values, this to avoid having scope_w be of mixed
-    # wrapped and unwrapped types;
-    # an exception is made for the NoneNotWrapped special value
-    # which is passed around as default as an unwrapped None,
-    # unwrapped None and wrapped types are compatible
-    #
     # Takes optionally an unwrap_spec, see BuiltinCode
 
-    NOT_RPYTHON_ATTRIBUTES = ['_staticdefs']
-
     instancecache = {}
 
     def __new__(cls, f, app_name=None, unwrap_spec=None, descrmismatch=None,
 
     def _getdefaults(self, space):
         "NOT_RPYTHON"
+        import pdb; pdb.set_trace()
         defs_w = []
         for val in self._staticdefs:
             if val is NoneNotWrapped:

File pypy/interpreter/generator.py

 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import NoneNotWrapped
 from pypy.interpreter.pyopcode import LoopBlock
 from pypy.rlib import jit
 from pypy.rlib.objectmodel import specialize

File pypy/interpreter/mixedmodule.py

 import inspect
 
 class MixedModule(Module):
-
-    NOT_RPYTHON_ATTRIBUTES = ['loaders']
-
     applevel_name = None
     expose__file__attribute = True
 

File pypy/interpreter/pycode.py

 from pypy.interpreter import eval
 from pypy.interpreter.argument import Signature
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import NoneNotWrapped, unwrap_spec
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.astcompiler.consts import (
     CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
     CO_GENERATOR, CO_CONTAINSGLOBALS)
                           argcount, nlocals, stacksize, flags,
                           codestring, w_constants, w_names,
                           w_varnames, filename, name, firstlineno,
-                          lnotab, w_freevars=NoneNotWrapped,
-                          w_cellvars=NoneNotWrapped,
+                          lnotab, w_freevars=None, w_cellvars=None,
                           magic=default_magic):
         if argcount < 0:
             raise OperationError(space.w_ValueError,

File pypy/module/_codecs/interp_codecs.py

 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import NoneNotWrapped, interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.rlib.rstring import UnicodeBuilder
 from pypy.rlib.objectmodel import we_are_translated
 
         raise OperationError(space.w_TypeError, space.wrap("invalid mapping"))
 
 
-@unwrap_spec(string=str, errors='str_or_None')
+@unwrap_spec(string=str, errors='str_or_None',
+             w_mapping = (W_Root, 'space.w_None'))
 def charmap_decode(space, string, errors="strict", w_mapping=None):
     if errors is None:
         errors = 'strict'
         final, state.decode_error_handler, mapping)
     return space.newtuple([space.wrap(result), space.wrap(consumed)])
 
-@unwrap_spec(uni=unicode, errors='str_or_None')
+@unwrap_spec(uni=unicode, errors='str_or_None',
+             w_mapping = (W_Root, 'space.w_None'))
 def charmap_encode(space, uni, errors="strict", w_mapping=None):
     if errors is None:
         errors = 'strict'

File pypy/module/_locale/interp_locale.py

 def setlocale(space, category, w_locale=None):
     "(integer,string=None) -> string. Activates/queries locale processing."
 
-    if space.is_w(w_locale, space.w_None) or w_locale is None:
+    if w_locale is None or space.is_w(w_locale, space.w_None):
         locale = None
     else:
         locale = space.str_w(w_locale)

File pypy/module/_socket/interp_func.py

         raise converted_error(space, e)
     return common_wrapgethost(space, res)
 
-@unwrap_spec(name=str)
-def getservbyname(space, name, w_proto=None):
+@unwrap_spec(name=str, w_proto = (W_Root, 'space.w_None'))
+def getservbyname(space, name, w_proto):
     """getservbyname(servicename[, protocolname]) -> integer
 
     Return a port number from a service name and protocol name.
         raise converted_error(space, e)
     return space.wrap(port)
 
-@unwrap_spec(port=int)
-def getservbyport(space, port, w_proto=None):
+@unwrap_spec(port=int, w_proto = (W_Root, 'space.w_None'))
+def getservbyport(space, port, w_proto):
     """getservbyport(port[, protocolname]) -> string
 
     Return the service name from a port number and protocol name.

File pypy/module/itertools/interp_itertools.py

         self.space = space
         self.w_obj = w_obj
 
-        if space.is_w(w_times, space.w_None):
+        if w_times is None:
             self.counting = False
             self.count = 0
         else:
                     self.new_group = True #new group
                     raise StopIteration
 
-def W_GroupBy___new__(space, w_subtype, w_iterable, w_key=None):
+@unwrap_spec(w_key = (W_Root, 'space.w_None'))
+def W_GroupBy___new__(space, w_subtype, w_iterable, w_key):
     r = space.allocate_instance(W_GroupBy, w_subtype)
     r.__init__(space, w_iterable, w_key)
     return space.wrap(r)
         self.stopped = True
         return w_result
 
-def W_Permutations__new__(space, w_subtype, w_iterable, w_r=None):
+@unwrap_spec(w_r = (W_Root, 'space.w_None'))
+def W_Permutations__new__(space, w_subtype, w_iterable, w_r):
     pool_w = space.fixedview(w_iterable)
     if space.is_w(w_r, space.w_None):
         r = len(pool_w)

File pypy/module/micronumpy/interp_arrayops.py

 from pypy.module.micronumpy.iter import Chunk, Chunks
 from pypy.module.micronumpy.strides import shape_agreement
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import unwrap_spec
+from pypy.interpreter.gateway import unwrap_spec, is_none
 
 def where(space, w_arr, w_x=None, w_y=None):
     """where(condition, [x, y])
 @unwrap_spec(repeats=int)
 def repeat(space, w_arr, repeats, w_axis=None):
     arr = convert_to_array(space, w_arr)
-    if space.is_w(w_axis, space.w_None):
+    if is_none(space, w_axis):
         arr = arr.descr_flatten(space)
         orig_size = arr.get_shape()[0]
         shape = [arr.get_shape()[0] * repeats]

File pypy/module/micronumpy/interp_numarray.py

 
 from pypy.interpreter.error import operationerrfmt, OperationError
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec, is_none
 from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
      ArrayArgumentException
 from pypy.module.micronumpy import interp_dtype, interp_ufuncs, interp_boxes
         return space.newlist(l_w)
 
     def descr_ravel(self, space, w_order=None):
-        if w_order is None or space.is_w(w_order, space.w_None):
+        if is_none(space, w_order):
             order = 'C'
         else:
             order = space.str_w(w_order)
         # if w_axis is None and w_out is Nont this is an equivalent to
         # fancy indexing
         raise Exception("unsupported for now")
-        if not space.is_w(w_axis, space.w_None):
+        if not is_none(space, w_axis):
             raise OperationError(space.w_NotImplementedError,
                                  space.wrap("axis unsupported for take"))
-        if not space.is_w(w_out, space.w_None):
+        if not is_none(space, w_out):
             raise OperationError(space.w_NotImplementedError,
                                  space.wrap("out unsupported for take"))
         return self.getitem_int(space, convert_to_array(space, w_obj))
 
     def descr_compress(self, space, w_obj, w_axis=None):
+        if not is_none(space, w_axis):
+            raise OperationError(space.w_NotImplementedError,
+                                 space.wrap("axis unsupported for compress"))
         index = convert_to_array(space, w_obj)
         return self.getitem_filter(space, index)
 
         return coords
 
     def descr_item(self, space, w_arg=None):
-        if space.is_w(w_arg, space.w_None):
+        if is_none(space, w_arg):
             if self.is_scalar():
                 return self.get_scalar_value().item(space)
             if self.get_size() == 1:

File pypy/module/select/interp_kqueue.py

     def descr_close(self, space):
         self.close()
 
-    @unwrap_spec(max_events=int)
-    def descr_control(self, space, w_changelist, max_events, w_timeout=None):
+    @unwrap_spec(max_events=int, w_timeout = (W_Root, 'space.w_None'))
+    def descr_control(self, space, w_changelist, max_events, w_timeout):
 
         self.check_closed(space)
 

File pypy/module/select/interp_select.py

             raise OperationError(space.w_KeyError,
                                  space.wrap(fd)) # XXX should this maybe be w_fd?
 
-    def poll(self, space, w_timeout=None):
+    @unwrap_spec(w_timeout = (W_Root, 'space.w_None'))
+    def poll(self, space, w_timeout):
         if space.is_w(w_timeout, space.w_None):
             timeout = -1
         else:
             reslist_w.append(list_w[i])
 
 
-def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout=None):
+@unwrap_spec(w_timeout = (W_Root, 'space.w_None'))
+def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout):
     """Wait until one or more file descriptors are ready for some kind of I/O.
 The first three arguments are sequences of file descriptors to be waited for:
 rlist -- wait until ready for reading

File pypy/objspace/std/booltype.py

-from pypy.interpreter import gateway
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.inttype import int_typedef
 
-def descr__new__(space, w_booltype, w_obj=None):
+@unwrap_spec(w_obj = (W_Root, 'space.w_False'))
+def descr__new__(space, w_booltype, w_obj):
     space.w_bool.check_user_subclass(w_booltype)
     if space.is_true(w_obj):
         return space.w_True
 Returns True when the argument x is true, False otherwise.
 The builtins True and False are the only two instances of the class bool.
 The class bool is a subclass of the class int, and cannot be subclassed.''',
-    __new__ = gateway.interp2app(descr__new__),
+    __new__ = interp2app(descr__new__),
     )
 bool_typedef.acceptable_as_base_class = False

File pypy/objspace/std/complextype.py

-from pypy.interpreter import gateway
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.strutil import string_to_float, ParseStringError
     return realpart, imagpart
 
 
-def descr__new__(space, w_complextype, w_real=0.0, w_imag=None):
+@unwrap_spec(w_real = (W_Root, 'space.wrap("0.0")'))
+def descr__new__(space, w_complextype, w_real, w_imag=None):
     from pypy.objspace.std.complexobject import W_ComplexObject
 
     # if w_real is already a complex number and there is no second
     # argument, return it.  Note that we cannot return w_real if
     # it is an instance of a *subclass* of complex, or if w_complextype
     # is itself a subclass of complex.
-    noarg2 = space.is_w(w_imag, space.w_None)
+    noarg2 = w_imag is None
     if (noarg2 and space.is_w(w_complextype, space.w_complex)
                and space.is_w(space.type(w_real), space.w_complex)):
         return w_real
 
 Create a complex number from a real part and an optional imaginary part.
 This is equivalent to (real + imag*1j) where imag defaults to 0.""",
-    __new__ = gateway.interp2app(descr__new__),
-    __getnewargs__ = gateway.interp2app(descr___getnewargs__),
+    __new__ = interp2app(descr__new__),
+    __getnewargs__ = interp2app(descr___getnewargs__),
     real = complexwprop('realval'),
     imag = complexwprop('imagval'),
     )

File pypy/objspace/std/formatting.py

     [_name[-1] for _name in dir(StringFormatter)
                if len(_name) == 5 and _name.startswith('fmt_')])
 
-def format(space, w_fmt, values_w, w_valuedict=None, do_unicode=False):
+def format(space, w_fmt, values_w, w_valuedict, do_unicode):
     "Entry point"
     if not do_unicode:
         fmt = space.str_w(w_fmt)

File pypy/objspace/std/test/test_complexobject.py

         assert '{0:F}'.format(complex(NAN, 0)) == 'NAN+0.000000j'
         assert '{0:f}'.format(complex(NAN, NAN)) == 'nan+nanj'
         assert '{0:F}'.format(complex(NAN, NAN)) == 'NAN+NANj'
+
+    def test_complex_two_arguments(self):
+        raises(TypeError, complex, 5, None)

File pypy/objspace/std/unicodetype.py

 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter import gateway
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
 from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.basestringtype import basestring_typedef
                              w_encoding, w_errors)
 
 
-def descr_new_(space, w_unicodetype, w_string='', w_encoding=None, w_errors=None):
+@unwrap_spec(w_string   = (W_Root, 'space.wrap("")'),
+             w_encoding = (W_Root, 'space.w_None'),
+             w_errors   = (W_Root, 'space.w_None'))
+def descr_new_(space, w_unicodetype, w_string, w_encoding, w_errors):
     # NB. the default value of w_obj is really a *wrapped* empty string:
     #     there is gateway magic at work
     from pypy.objspace.std.unicodeobject import W_UnicodeObject
 # ____________________________________________________________
 
 unicode_typedef = StdTypeDef("unicode", basestring_typedef,
-    __new__ = gateway.interp2app(descr_new_),
+    __new__ = interp2app(descr_new_),
     __doc__ = '''unicode(string [, encoding[, errors]]) -> object
 
 Create a new Unicode object from the given encoded string.