Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r69921:a0911b1c0cb1 Date: 2014-03-12 19:38 -0700 http://bitbucket.org/pypy/pypy/changeset/a0911b1c0cb1/
Log: add int.__ceil/floor__, cleanup diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py --- a/pypy/objspace/std/intobject.py +++ b/pypy/objspace/std/intobject.py @@ -177,11 +177,25 @@ _, w_r = space.fixedview(w_tuple, 2) return space.sub(self, w_r) - def _int(self, space): - return self.int(space) + def _self_unaryop(opname, doc=None): + @func_renamer('descr_' + opname) + def descr_unaryop(self, space): + return self.int(space) + descr_unaryop.__doc__ = doc + return descr_unaryop - descr_get_numerator = func_with_new_name(_int, 'descr_get_numerator') - descr_get_real = func_with_new_name(_int, 'descr_get_real') + descr_conjugate = _self_unaryop( + 'conjugate', "Returns self, the complex conjugate of any int.") + descr_pos = _self_unaryop('pos', "x.__pos__() <==> +x") + descr_index = _self_unaryop('index', + "x[y:z] <==> x[y.__index__():z.__index__()]") + descr_trunc = _self_unaryop('trunc', + "Truncating an Integral returns itself.") + descr_floor = _self_unaryop('floor', "Flooring an Integral returns itself.") + descr_ceil = _self_unaryop('ceil', "Ceiling of an Integral returns itself.") + + descr_get_numerator = _self_unaryop('get_numerator') + descr_get_real = _self_unaryop('get_real') def descr_get_denominator(self, space): return wrapint(space, 1) @@ -217,8 +231,6 @@ descr_repr = _abstract_unaryop('repr') descr_str = _abstract_unaryop('str') - descr_conjugate = _abstract_unaryop( - 'conjugate', "Returns self, the complex conjugate of any int.") descr_bit_length = _abstract_unaryop('bit_length', """\ int.bit_length() -> int @@ -229,14 +241,7 @@ 6""") descr_hash = _abstract_unaryop('hash') descr_getnewargs = _abstract_unaryop('getnewargs', None) - - descr_index = _abstract_unaryop( - 'index', "x[y:z] <==> x[y.__index__():z.__index__()]") - descr_trunc = _abstract_unaryop('trunc', - "Truncating an Integral returns itself.") descr_float = _abstract_unaryop('float') - - descr_pos = _abstract_unaryop('pos', "x.__pos__() <==> +x") descr_neg = _abstract_unaryop('neg', "x.__neg__() <==> -x") descr_abs = _abstract_unaryop('abs') descr_bool = _abstract_unaryop('bool', "x.__bool__() <==> x != 0") @@ -531,14 +536,6 @@ x = intmask(intmask(x) * sign) return wrapint(space, -2 if x == -1 else x) - def _int(self, space): - return self.int(space) - - descr_pos = func_with_new_name(_int, 'descr_pos') - descr_index = func_with_new_name(_int, 'descr_index') - descr_trunc = func_with_new_name(_int, 'descr_trunc') - descr_conjugate = func_with_new_name(_int, 'descr_conjugate') - def as_w_long(self, space): # XXX: should try smalllong from pypy.objspace.std.longobject import W_LongObject @@ -990,6 +987,8 @@ __abs__ = interpindirect2app(W_AbstractIntObject.descr_abs), __bool__ = interpindirect2app(W_AbstractIntObject.descr_bool), __invert__ = interpindirect2app(W_AbstractIntObject.descr_invert), + __floor__ = interpindirect2app(W_AbstractIntObject.descr_floor), + __ceil__ = interpindirect2app(W_AbstractIntObject.descr_ceil), __lt__ = interpindirect2app(W_AbstractIntObject.descr_lt), __le__ = interpindirect2app(W_AbstractIntObject.descr_le), diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py --- a/pypy/objspace/std/longobject.py +++ b/pypy/objspace/std/longobject.py @@ -43,9 +43,6 @@ def descr_getnewargs(self, space): return space.newtuple([newlong(space, self.asbigint())]) - def descr_conjugate(self, space): - return self.int(space) - def descr_bit_length(self, space): bigint = space.bigint_w(self) try: @@ -164,8 +161,6 @@ def __repr__(self): return '<W_LongObject(%d)>' % self.num.tolong() - descr_index = descr_trunc = descr_pos = int - def descr_float(self, space): return space.newfloat(self.tofloat(space)) diff --git a/pypy/objspace/std/smalllongobject.py b/pypy/objspace/std/smalllongobject.py --- a/pypy/objspace/std/smalllongobject.py +++ b/pypy/objspace/std/smalllongobject.py @@ -79,8 +79,6 @@ return W_LongObject(self.num) return W_Root.int(self, space) - descr_index = descr_trunc = descr_pos = int - def descr_float(self, space): return space.newfloat(float(self.longlong)) diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py --- a/pypy/objspace/std/test/test_intobject.py +++ b/pypy/objspace/std/test/test_intobject.py @@ -551,6 +551,12 @@ assert ns['a'] == 9007199254740991.0 assert ns['b'] == 9007199254740991.0 + def test_ceil(self): + assert 8 .__ceil__() == 8 + + def test_floor(self): + assert 8 .__floor__() == 8 + class AppTestIntShortcut(AppTestInt): spaceconfig = {"objspace.std.intshortcut": True} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit