Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r87050:a8137a62856a Date: 2016-09-12 18:14 +0200 http://bitbucket.org/pypy/pypy/changeset/a8137a62856a/
Log: Fix for argument clinic's use of the "bool" specifier, which now maps to "unwrap_spec(...=bool)". diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1232,7 +1232,7 @@ if e.match(self, self.w_AttributeError): return False raise - return self.bool_w(self.nonzero(w_result)) + return self.is_true(self.nonzero(w_result)) # CPython rules allows subclasses of BaseExceptions to be exceptions. # This is slightly less general than the case above, so we prefix @@ -1683,7 +1683,9 @@ def bool_w(self, w_obj): # Unwraps a bool, also accepting an int for compatibility. - # This is here mostly just for gateway.int_unwrapping_space_method(). + # For cases where you need to accept bools and ints and nothing + # else. Note that saying 'bool' in unwrap_spec() doesn't call + # this, but the general is_true(), accepting any object. return bool(self.int_w(w_obj)) def ord(self, w_obj): diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py --- a/pypy/interpreter/gateway.py +++ b/pypy/interpreter/gateway.py @@ -520,8 +520,17 @@ assert typ in (int, str, float, unicode, r_longlong, r_uint, r_ulonglong, bool) if typ is r_int is r_longlong: return 'gateway_r_longlong_w' - elif typ in (str, unicode, bool): + elif typ in (str, unicode): return typ.__name__ + '_w' + elif typ is bool: + # For argument clinic's "bool" specifier: accept any object, and + # convert it to a boolean value. If you don't want this + # behavior, you need to say "int" in the unwrap_spec(). Please + # use only to emulate "bool" in argument clinic or the 'p' + # letter in PyArg_ParseTuple(). Accepting *anything* when a + # boolean flag is expected feels like it comes straight from + # JavaScript: it is a sure way to hide bugs imho <arigo>. + return 'is_true' else: return 'gateway_' + typ.__name__ + '_w' diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py --- a/pypy/module/_io/interp_io.py +++ b/pypy/module/_io/interp_io.py @@ -21,7 +21,7 @@ @unwrap_spec(mode=str, buffering=int, encoding="str_or_None", errors="str_or_None", - newline="str_or_None", closefd=bool) + newline="str_or_None", closefd=int) def open(space, w_file, mode="r", buffering=-1, encoding=None, errors=None, newline=None, closefd=True, w_opener=None): from pypy.module._io.interp_bufferedio import (W_BufferedRandom, @@ -88,7 +88,7 @@ "binary mode doesn't take a newline argument") w_raw = space.call_function( space.gettypefor(W_FileIO), w_file, space.wrap(rawmode), - space.wrap(closefd), w_opener) + space.wrap(bool(closefd)), w_opener) isatty = space.is_true(space.call_method(w_raw, "isatty")) line_buffering = buffering == 1 or (buffering < 0 and isatty) diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py --- a/pypy/module/_lsprof/interp_lsprof.py +++ b/pypy/module/_lsprof/interp_lsprof.py @@ -434,11 +434,11 @@ return stats(space, self.data.values() + self.builtin_data.values(), factor) -@unwrap_spec(time_unit=float, subcalls=bool, builtins=bool) +@unwrap_spec(time_unit=float, subcalls=int, builtins=int) def descr_new_profile(space, w_type, w_callable=None, time_unit=0.0, - subcalls=True, builtins=True): + subcalls=1, builtins=1): p = space.allocate_instance(W_Profiler, w_type) - p.__init__(space, w_callable, time_unit, subcalls, builtins) + p.__init__(space, w_callable, time_unit, bool(subcalls), bool(builtins)) return space.wrap(p) W_Profiler.typedef = TypeDef( diff --git a/pypy/module/_multibytecodec/interp_incremental.py b/pypy/module/_multibytecodec/interp_incremental.py --- a/pypy/module/_multibytecodec/interp_incremental.py +++ b/pypy/module/_multibytecodec/interp_incremental.py @@ -48,8 +48,9 @@ c_codecs.pypy_cjk_dec_free(self.decodebuf) self.decodebuf = lltype.nullptr(c_codecs.DECODEBUF_P.TO) - @unwrap_spec(object='bufferstr', final=bool) - def decode_w(self, object, final=False): + @unwrap_spec(object='bufferstr', final=int) + def decode_w(self, object, final=0): + final = bool(final) space = self.space state = space.fromcache(CodecState) if len(self.pending) > 0: @@ -96,8 +97,9 @@ c_codecs.pypy_cjk_enc_free(self.encodebuf) self.encodebuf = lltype.nullptr(c_codecs.ENCODEBUF_P.TO) - @unwrap_spec(object=unicode, final=bool) - def encode_w(self, object, final=False): + @unwrap_spec(object=unicode, final=int) + def encode_w(self, object, final=0): + final = bool(final) space = self.space state = space.fromcache(CodecState) if len(self.pending) > 0: diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py --- a/pypy/module/_rawffi/array.py +++ b/pypy/module/_rawffi/array.py @@ -36,9 +36,9 @@ def get_basic_ffi_type(self): return self.basicffitype - @unwrap_spec(length=int, autofree=bool) + @unwrap_spec(length=int, autofree=int) def descr_call(self, space, length, w_items=None, autofree=False): - result = self.allocate(space, length, autofree) + result = self.allocate(space, length, bool(autofree)) if not space.is_none(w_items): items_w = space.unpackiterable(w_items) iterlength = len(items_w) diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py --- a/pypy/module/_rawffi/structure.py +++ b/pypy/module/_rawffi/structure.py @@ -189,9 +189,9 @@ raise oefmt(space.w_AttributeError, "C Structure has no attribute %s", attr) - @unwrap_spec(autofree=bool) + @unwrap_spec(autofree=int) def descr_call(self, space, autofree=False): - return space.wrap(self.allocate(space, 1, autofree)) + return space.wrap(self.allocate(space, 1, bool(autofree))) def descr_repr(self, space): fieldnames = ' '.join(["'%s'" % name for name, _, _ in self.fields]) @@ -248,8 +248,9 @@ lltype.free(self.ffi_struct, flavor='raw') -@unwrap_spec(union=bool, pack=int) -def descr_new_structure(space, w_type, w_shapeinfo, union=False, pack=0): +@unwrap_spec(union=int, pack=int) +def descr_new_structure(space, w_type, w_shapeinfo, union=0, pack=0): + union = bool(union) if pack < 0: raise oefmt(space.w_ValueError, "_pack_ must be a non-negative integer") diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py --- a/pypy/module/_socket/interp_socket.py +++ b/pypy/module/_socket/interp_socket.py @@ -453,7 +453,7 @@ raise converted_error(space, e) return space.wrap(count) - @unwrap_spec(flag=bool) + @unwrap_spec(flag=int) def setblocking_w(self, flag): """setblocking(flag) @@ -461,7 +461,7 @@ setblocking(True) is equivalent to settimeout(None); setblocking(False) is equivalent to settimeout(0.0). """ - self.sock.setblocking(flag) + self.sock.setblocking(bool(flag)) @unwrap_spec(level=int, optname=int) def setsockopt_w(self, space, level, optname, w_optval): diff --git a/pypy/module/posix/interp_scandir.py b/pypy/module/posix/interp_scandir.py --- a/pypy/module/posix/interp_scandir.py +++ b/pypy/module/posix/interp_scandir.py @@ -267,13 +267,13 @@ return known_type == rposix_scandir.DT_LNK return self.check_mode(follow_symlinks=False) == stat.S_IFLNK - @unwrap_spec(follow_symlinks=int) - def descr_is_dir(self, space, __kwonly__, follow_symlinks=1): + @unwrap_spec(follow_symlinks=bool) + def descr_is_dir(self, space, __kwonly__, follow_symlinks=True): """return True if the entry is a directory; cached per entry""" return space.wrap(self.is_dir(follow_symlinks)) - @unwrap_spec(follow_symlinks=int) - def descr_is_file(self, space, __kwonly__, follow_symlinks=1): + @unwrap_spec(follow_symlinks=bool) + def descr_is_file(self, space, __kwonly__, follow_symlinks=True): """return True if the entry is a file; cached per entry""" return space.wrap(self.is_file(follow_symlinks)) @@ -281,8 +281,8 @@ """return True if the entry is a symbolic link; cached per entry""" return space.wrap(self.is_symlink()) - @unwrap_spec(follow_symlinks=int) - def descr_stat(self, space, __kwonly__, follow_symlinks=1): + @unwrap_spec(follow_symlinks=bool) + def descr_stat(self, space, __kwonly__, follow_symlinks=True): """return stat_result object for the entry; cached per entry""" st = self.get_stat_or_lstat(follow_symlinks) return build_stat_result(self.space, st) diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py --- a/pypy/module/pyexpat/interp_pyexpat.py +++ b/pypy/module/pyexpat/interp_pyexpat.py @@ -634,7 +634,7 @@ # Parse methods - @unwrap_spec(isfinal=bool) + @unwrap_spec(isfinal=int) def Parse(self, space, w_data, isfinal=False): """Parse(data[, isfinal]) Parse XML data. `isfinal' should be true at end of input.""" @@ -645,6 +645,7 @@ XML_SetEncoding(self.itself, "utf-8") else: data = space.bufferstr_w(w_data) + isfinal = bool(isfinal) res = XML_Parse(self.itself, data, len(data), isfinal) if self._exc_info: e = self._exc_info diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py --- a/pypy/module/pypyjit/interp_jit.py +++ b/pypy/module/pypyjit/interp_jit.py @@ -210,27 +210,27 @@ ) W_NotFromAssembler.typedef.acceptable_as_base_class = False -@unwrap_spec(next_instr=int, is_being_profiled=bool, w_pycode=PyCode) +@unwrap_spec(next_instr=int, is_being_profiled=int, w_pycode=PyCode) @dont_look_inside def get_jitcell_at_key(space, next_instr, is_being_profiled, w_pycode): ll_pycode = cast_instance_to_gcref(w_pycode) return space.wrap(bool(jit_hooks.get_jitcell_at_key( - 'pypyjit', r_uint(next_instr), int(is_being_profiled), ll_pycode))) + 'pypyjit', r_uint(next_instr), int(bool(is_being_profiled)), ll_pycode))) -@unwrap_spec(next_instr=int, is_being_profiled=bool, w_pycode=PyCode) +@unwrap_spec(next_instr=int, is_being_profiled=int, w_pycode=PyCode) @dont_look_inside def dont_trace_here(space, next_instr, is_being_profiled, w_pycode): ll_pycode = cast_instance_to_gcref(w_pycode) jit_hooks.dont_trace_here( - 'pypyjit', r_uint(next_instr), int(is_being_profiled), ll_pycode) + 'pypyjit', r_uint(next_instr), int(bool(is_being_profiled)), ll_pycode) return space.w_None -@unwrap_spec(next_instr=int, is_being_profiled=bool, w_pycode=PyCode) +@unwrap_spec(next_instr=int, is_being_profiled=int, w_pycode=PyCode) @dont_look_inside def trace_next_iteration(space, next_instr, is_being_profiled, w_pycode): ll_pycode = cast_instance_to_gcref(w_pycode) jit_hooks.trace_next_iteration( - 'pypyjit', r_uint(next_instr), int(is_being_profiled), ll_pycode) + 'pypyjit', r_uint(next_instr), int(bool(is_being_profiled)), ll_pycode) return space.w_None @unwrap_spec(hash=r_uint) diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py --- a/pypy/module/pypyjit/interp_resop.py +++ b/pypy/module/pypyjit/interp_resop.py @@ -44,8 +44,8 @@ else: return space.wrap(greenkey_repr) -@unwrap_spec(operations=bool) -def set_compile_hook(space, w_hook, operations=True): +@unwrap_spec(operations=int) +def set_compile_hook(space, w_hook, operations=1): """ set_compile_hook(hook, operations=True) Set a compiling hook that will be called each time a loop is compiled. @@ -60,7 +60,7 @@ cache = space.fromcache(Cache) assert w_hook is not None cache.w_compile_hook = w_hook - cache.compile_hook_with_ops = operations + cache.compile_hook_with_ops = bool(operations) cache.in_recursion = NonConstant(False) def set_abort_hook(space, w_hook): diff --git a/pypy/module/thread/os_lock.py b/pypy/module/thread/os_lock.py --- a/pypy/module/thread/os_lock.py +++ b/pypy/module/thread/os_lock.py @@ -169,7 +169,7 @@ return space.wrap(u"<%s owner=%d count=%d>" % ( typename, self.rlock_owner, self.rlock_count)) - @unwrap_spec(blocking=bool, timeout=float) + @unwrap_spec(blocking=int, timeout=float) def acquire_w(self, space, blocking=True, timeout=-1.0): """Lock the lock. `blocking` indicates whether we should wait for the lock to be available or not. If `blocking` is False diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -677,7 +677,7 @@ raise oefmt(space.w_ValueError, "%R is not in list", w_value) return space.wrap(i) - @unwrap_spec(reverse=bool) + @unwrap_spec(reverse=int) def descr_sort(self, space, w_key=None, reverse=False): """ L.sort(key=None, reverse=False) -- stable sort *IN PLACE*""" diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py --- a/pypy/objspace/std/stringmethods.py +++ b/pypy/objspace/std/stringmethods.py @@ -564,7 +564,7 @@ return self._newlist_unwrapped(space, res) - @unwrap_spec(keepends=bool) + @unwrap_spec(keepends=int) def descr_splitlines(self, space, keepends=False): value = self._val(space) length = len(value) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit