Commits

Alex Gaynor committed 442dd20

Convert from __nonzero__ to __bool__.

  • Participants
  • Parent commits a1ae5b4
  • Branches py3k

Comments (0)

Files changed (12)

File lib_pypy/_ctypes/function.py

                 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):
             self._check_argtypes_for_fastpath()
             return
 
-        
+
         # A callback into python
         if callable(argument) and not argsl:
             self.callable = argument
                         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:
             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]
         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_'):
     @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
 
         return retval
 
-    def __nonzero__(self):
+    def __bool__(self):
         return self._com_index is not None or bool(self._buffer[0])
 
     def __del__(self):

File lib_pypy/_ctypes/pointer.py

             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)

File lib_pypy/_ctypes/primitive.py

                 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):
             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
     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)
         if self.__bases__[0] is _SimpleCData:
             return output.value
         return output
-    
+
     def _sizeofinstances(self):
         return _rawffi.sizeof(self._type_)
 
             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

File lib_pypy/greenlet.py

         else:
             return args
 
-    def __nonzero__(self):
+    def __bool__(self):
         return self.__main or _continulet.is_pending(self)
 
     @property

File pypy/interpreter/baseobjspace.py

     ('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__']),

File pypy/module/__builtin__/test/test_functional.py

     def test_all(self):
 
         class TestFailingBool(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 raise RuntimeError
         class TestFailingIter(object):
             def __iter__(self):
     def test_any(self):
 
         class TestFailingBool(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 raise RuntimeError
         class TestFailingIter(object):
             def __iter__(self):

File pypy/module/_winreg/interp_winreg.py

     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):
 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),

File pypy/module/cpyext/slotdefs.py

         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, "<<"),

File pypy/module/cpyext/test/test_object.py

 
     def test_exception(self, space, api):
         class C:
-            def __nonzero__(self):
+            def __bool__(self):
                 raise ValueError
 
         assert api.PyObject_IsTrue(space.wrap(C())) == -1
 
     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),
         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
             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

File pypy/objspace/descroperation.py

         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__"

File pypy/objspace/std/builtinshortcut.py

 
 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
         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):

File pypy/objspace/test/test_descroperation.py

         class myint(int):
             pass
         class X(object):
-            def __nonzero__(self):
+            def __bool__(self):
                 return myint(1)
         raises(TypeError, "not X()")
 
     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):