Author: Alex Gaynor <[email protected]>
Branch: py3k
Changeset: r48953:442dd206f22d
Date: 2011-11-08 11:25 -0500
http://bitbucket.org/pypy/pypy/changeset/442dd206f22d/
Log: Convert from __nonzero__ to __bool__.
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -157,11 +157,11 @@
callable(restype)):
raise TypeError("restype must be a type, a callable, or None")
self._restype_ = restype
-
+
def _delrestype(self):
self._ptr = None
del self._restype_
-
+
restype = property(_getrestype, _setrestype, _delrestype)
def _geterrcheck(self):
@@ -221,7 +221,7 @@
self._check_argtypes_for_fastpath()
return
-
+
# A callback into python
if callable(argument) and not argsl:
self.callable = argument
@@ -274,7 +274,7 @@
for argtype, arg in zip(argtypes, args)]
return to_call(*args)
return f
-
+
def __call__(self, *args, **kwargs):
argtypes = self._argtypes_
if self.callable is not None:
@@ -405,7 +405,7 @@
ffiargs = [argtype.get_ffi_argtype() for argtype in argtypes]
ffires = restype.get_ffi_argtype()
return _ffi.FuncPtr.fromaddr(ptr, '', ffiargs, ffires)
-
+
cdll = self.dll._handle
try:
ffi_argtypes = [argtype.get_ffi_argtype() for argtype in argtypes]
@@ -439,7 +439,7 @@
if isinstance(argtype, _CDataMeta):
cobj, ffiparam = argtype.get_ffi_param(arg)
return cobj, ffiparam, argtype
-
+
if argtype is not None:
arg = argtype.from_param(arg)
if hasattr(arg, '_as_parameter_'):
@@ -570,7 +570,7 @@
@staticmethod
def _is_primitive(argtype):
return argtype.__bases__[0] is _SimpleCData
-
+
def _wrap_result(self, restype, result):
"""
Convert from low-level repr of the result to the high-level python
@@ -630,7 +630,7 @@
return retval
- def __nonzero__(self):
+ def __bool__(self):
return self._com_index is not None or bool(self._buffer[0])
def __del__(self):
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -111,7 +111,7 @@
store_reference(self, index, cobj._objects)
self._subarray(index)[0] = cobj._get_buffer_value()
- def __nonzero__(self):
+ def __bool__(self):
return self._buffer[0] != 0
contents = property(getcontents, setcontents)
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -186,8 +186,8 @@
elif value is None:
value = 0
self._buffer[0] = value
- result.value = property(_getvalue, _setvalue)
-
+ result.value = property(_getvalue, _setvalue)
+
elif tp == 'u':
def _setvalue(self, val):
if isinstance(val, str):
@@ -264,7 +264,7 @@
def _as_ffi_pointer_(self, ffitype):
return as_ffi_pointer(self, ffitype)
result._as_ffi_pointer_ = _as_ffi_pointer_
-
+
return result
from_address = cdata_from_address
@@ -272,7 +272,7 @@
def from_param(self, value):
if isinstance(value, self):
return value
-
+
from_param_f = FROM_PARAM_BY_TYPE.get(self._type_)
if from_param_f:
res = from_param_f(self, value)
@@ -291,7 +291,7 @@
if self.__bases__[0] is _SimpleCData:
return output.value
return output
-
+
def _sizeofinstances(self):
return _rawffi.sizeof(self._type_)
@@ -338,7 +338,7 @@
return "<%s object at 0x%x>" % (type(self).__name__,
id(self))
- def __nonzero__(self):
+ def __bool__(self):
return self._buffer[0] not in (0, '\x00')
from _ctypes.function import CFuncPtr
diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -87,7 +87,7 @@
else:
return args
- def __nonzero__(self):
+ def __bool__(self):
return self.__main or _continulet.is_pending(self)
@property
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1483,7 +1483,7 @@
('trunc', 'trunc', 1, ['__trunc__']),
('pos', 'pos', 1, ['__pos__']),
('neg', 'neg', 1, ['__neg__']),
- ('nonzero', 'truth', 1, ['__nonzero__']),
+ ('nonzero', 'truth', 1, ['__bool__']),
('abs' , 'abs', 1, ['__abs__']),
('hex', 'hex', 1, ['__hex__']),
('oct', 'oct', 1, ['__oct__']),
diff --git a/pypy/module/__builtin__/test/test_functional.py
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -189,7 +189,7 @@
def test_all(self):
class TestFailingBool(object):
- def __nonzero__(self):
+ def __bool__(self):
raise RuntimeError
class TestFailingIter(object):
def __iter__(self):
@@ -211,7 +211,7 @@
def test_any(self):
class TestFailingBool(object):
- def __nonzero__(self):
+ def __bool__(self):
raise RuntimeError
class TestFailingIter(object):
def __iter__(self):
diff --git a/pypy/module/_winreg/interp_winreg.py
b/pypy/module/_winreg/interp_winreg.py
--- a/pypy/module/_winreg/interp_winreg.py
+++ b/pypy/module/_winreg/interp_winreg.py
@@ -23,7 +23,7 @@
def as_int(self):
return rffi.cast(rffi.SIZE_T, self.hkey)
- def descr_nonzero(self, space):
+ def descr_bool(self, space):
return space.wrap(self.as_int() != 0)
def descr_handle_get(self, space):
@@ -87,14 +87,14 @@
handle - The integer Win32 handle.
Operations:
-__nonzero__ - Handles with an open object return true, otherwise false.
+__bool__ - Handles with an open object return true, otherwise false.
__int__ - Converting a handle to an integer returns the Win32 handle.
__cmp__ - Handle objects are compared using the handle value.""",
__new__ = descr_HKEY_new,
__del__ = interp2app(W_HKEY.descr_del),
__repr__ = interp2app(W_HKEY.descr_repr),
__int__ = interp2app(W_HKEY.descr_int),
- __nonzero__ = interp2app(W_HKEY.descr_nonzero),
+ __bool__ = interp2app(W_HKEY.descr_bool),
__enter__ = interp2app(W_HKEY.descr__enter__),
__exit__ = interp2app(W_HKEY.descr__exit__),
handle = GetSetProperty(W_HKEY.descr_handle_get),
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -473,7 +473,7 @@
UNSLOT("__pos__", nb_positive, slot_nb_positive, wrap_unaryfunc, "+x"),
UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc,
"abs(x)"),
- UNSLOT("__nonzero__", nb_nonzero, slot_nb_nonzero, wrap_inquirypred,
+ UNSLOT("__bool__", nb_bool, slot_nb_bool, wrap_inquirypred,
"x != 0"),
UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~x"),
BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"),
diff --git a/pypy/module/cpyext/test/test_object.py
b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -20,7 +20,7 @@
def test_exception(self, space, api):
class C:
- def __nonzero__(self):
+ def __bool__(self):
raise ValueError
assert api.PyObject_IsTrue(space.wrap(C())) == -1
@@ -90,27 +90,27 @@
def test_size(self, space, api):
assert api.PyObject_Size(space.newlist([space.w_None])) == 1
-
+
def test_repr(self, space, api):
w_list = space.newlist([space.w_None, space.wrap(42)])
assert space.str_w(api.PyObject_Repr(w_list)) == "[None, 42]"
assert space.str_w(api.PyObject_Repr(space.wrap("a"))) == "'a'"
-
+
w_list = space.newlist([space.w_None, space.wrap(42)])
assert space.str_w(api.PyObject_Str(w_list)) == "[None, 42]"
assert space.str_w(api.PyObject_Str(space.wrap("a"))) == "a"
-
+
def test_RichCompare(self, space, api):
def compare(w_o1, w_o2, opid):
res = api.PyObject_RichCompareBool(w_o1, w_o2, opid)
w_res = api.PyObject_RichCompare(w_o1, w_o2, opid)
assert space.is_true(w_res) == res
return res
-
+
def test_compare(o1, o2):
w_o1 = space.wrap(o1)
w_o2 = space.wrap(o2)
-
+
for opid, expected in [
(Py_LT, o1 < o2), (Py_LE, o1 <= o2),
(Py_NE, o1 != o2), (Py_EQ, o1 == o2),
@@ -120,12 +120,12 @@
test_compare(1, 2)
test_compare(2, 2)
test_compare('2', '1')
-
+
w_i = space.wrap(1)
assert api.PyObject_RichCompareBool(w_i, w_i, 123456) == -1
assert api.PyErr_Occurred() is space.w_SystemError
api.PyErr_Clear()
-
+
def test_IsInstance(self, space, api):
assert api.PyObject_IsInstance(space.wrap(1), space.w_int) == 1
assert api.PyObject_IsInstance(space.wrap(1), space.w_float) == 0
@@ -158,7 +158,7 @@
return File""")
w_f = space.call_function(w_File)
assert api.PyObject_AsFileDescriptor(w_f) == 42
-
+
def test_hash(self, space, api):
assert api.PyObject_Hash(space.wrap(72)) == 72
assert api.PyObject_Hash(space.wrap(-1)) == -1
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -222,7 +222,7 @@
return space.get_and_call_function(w_descr, w_obj, w_name)
def is_true(space, w_obj):
- method = "__nonzero__"
+ method = "__bool__"
w_descr = space.lookup(w_obj, method)
if w_descr is None:
method = "__len__"
diff --git a/pypy/objspace/std/builtinshortcut.py
b/pypy/objspace/std/builtinshortcut.py
--- a/pypy/objspace/std/builtinshortcut.py
+++ b/pypy/objspace/std/builtinshortcut.py
@@ -50,7 +50,7 @@
def filter_out_conversions(typeorder):
res = {}
- for cls, order in typeorder.iteritems():
+ for cls, order in typeorder.iteritems():
res[cls] = [(target_type, converter) for (target_type, converter) in
order if converter is None]
return res
@@ -113,7 +113,7 @@
except FailedToImplement:
pass
else:
- # the __nonzero__ method of built-in objects should
+ # the __bool__ method of built-in objects should
# always directly return a Bool; however, the __len__ method
# of built-in objects typically returns an unwrappable integer
if isinstance(w_res, W_BoolObject):
diff --git a/pypy/objspace/test/test_descroperation.py
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -228,7 +228,7 @@
class myint(int):
pass
class X(object):
- def __nonzero__(self):
+ def __bool__(self):
return myint(1)
raises(TypeError, "not X()")
@@ -640,9 +640,9 @@
def test_truth_of_long(self):
class X(object):
def __len__(self): return 1L
- __nonzero__ = __len__
+ __bool__ = __len__
assert X()
- del X.__nonzero__
+ del X.__bool__
assert X()
def test_len_overflow(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit