Author: Armin Rigo <ar...@tunes.org> Branch: kill-someobject Changeset: r57971:cccfbccb0b5a Date: 2012-10-10 14:48 +0200 http://bitbucket.org/pypy/pypy/changeset/cccfbccb0b5a/
Log: (fijal, arigo) in-progress: refactoring the NoneNotWrapped away, yay diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py --- a/pypy/interpreter/gateway.py +++ b/pypy/interpreter/gateway.py @@ -13,8 +13,6 @@ 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, @@ -97,6 +95,10 @@ 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) + #________________________________________________________________ @@ -519,8 +521,6 @@ # 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. @@ -802,17 +802,8 @@ 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, @@ -854,6 +845,7 @@ def _getdefaults(self, space): "NOT_RPYTHON" + import pdb; pdb.set_trace() defs_w = [] for val in self._staticdefs: if val is NoneNotWrapped: diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -1,6 +1,5 @@ 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 diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py --- a/pypy/interpreter/mixedmodule.py +++ b/pypy/interpreter/mixedmodule.py @@ -8,9 +8,6 @@ import inspect class MixedModule(Module): - - NOT_RPYTHON_ATTRIBUTES = ['loaders'] - applevel_name = None expose__file__attribute = True diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py --- a/pypy/interpreter/pycode.py +++ b/pypy/interpreter/pycode.py @@ -9,7 +9,7 @@ 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) @@ -342,8 +342,7 @@ 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, 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,5 +1,5 @@ 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 @@ -598,7 +598,8 @@ 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' @@ -617,7 +618,8 @@ 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' diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py --- a/pypy/module/_locale/interp_locale.py +++ b/pypy/module/_locale/interp_locale.py @@ -48,7 +48,7 @@ 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) diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py --- a/pypy/module/_socket/interp_func.py +++ b/pypy/module/_socket/interp_func.py @@ -61,8 +61,8 @@ 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. @@ -79,8 +79,8 @@ 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. diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py --- a/pypy/module/itertools/interp_itertools.py +++ b/pypy/module/itertools/interp_itertools.py @@ -87,7 +87,7 @@ 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: @@ -966,7 +966,8 @@ 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) @@ -1336,7 +1337,8 @@ 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) diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py --- a/pypy/module/micronumpy/interp_arrayops.py +++ b/pypy/module/micronumpy/interp_arrayops.py @@ -4,7 +4,7 @@ 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]) @@ -127,7 +127,7 @@ @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] diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py --- a/pypy/module/micronumpy/interp_numarray.py +++ b/pypy/module/micronumpy/interp_numarray.py @@ -1,7 +1,7 @@ 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 @@ -293,7 +293,7 @@ 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) @@ -306,15 +306,18 @@ # 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) @@ -341,7 +344,7 @@ 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: diff --git a/pypy/module/select/interp_kqueue.py b/pypy/module/select/interp_kqueue.py --- a/pypy/module/select/interp_kqueue.py +++ b/pypy/module/select/interp_kqueue.py @@ -143,8 +143,8 @@ 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) diff --git a/pypy/module/select/interp_select.py b/pypy/module/select/interp_select.py --- a/pypy/module/select/interp_select.py +++ b/pypy/module/select/interp_select.py @@ -41,7 +41,8 @@ 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: @@ -100,7 +101,8 @@ 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 diff --git a/pypy/objspace/std/booltype.py b/pypy/objspace/std/booltype.py --- a/pypy/objspace/std/booltype.py +++ b/pypy/objspace/std/booltype.py @@ -1,8 +1,9 @@ -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 @@ -17,6 +18,6 @@ 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 diff --git a/pypy/objspace/std/complextype.py b/pypy/objspace/std/complextype.py --- a/pypy/objspace/std/complextype.py +++ b/pypy/objspace/std/complextype.py @@ -1,4 +1,4 @@ -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 @@ -115,14 +115,15 @@ 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 @@ -232,8 +233,8 @@ 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'), ) diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -500,7 +500,7 @@ [_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) diff --git a/pypy/objspace/std/test/test_complexobject.py b/pypy/objspace/std/test/test_complexobject.py --- a/pypy/objspace/std/test/test_complexobject.py +++ b/pypy/objspace/std/test/test_complexobject.py @@ -570,3 +570,6 @@ 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) diff --git a/pypy/objspace/std/unicodetype.py b/pypy/objspace/std/unicodetype.py --- a/pypy/objspace/std/unicodetype.py +++ b/pypy/objspace/std/unicodetype.py @@ -1,5 +1,5 @@ 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 @@ -335,7 +335,10 @@ 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 @@ -375,7 +378,7 @@ # ____________________________________________________________ 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. _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit