Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r87330:a48793436b6d Date: 2016-09-22 17:49 +0200 http://bitbucket.org/pypy/pypy/changeset/a48793436b6d/
Log: hg merge py3k diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py --- a/pypy/interpreter/argument.py +++ b/pypy/interpreter/argument.py @@ -198,7 +198,6 @@ input_argcount += take # collect extra positional arguments into the *vararg - kwonly_given = 0 if signature.has_vararg(): args_left = co_argcount - upfront if args_left < 0: # check required by rpython @@ -212,9 +211,6 @@ loc = co_argcount + co_kwonlyargcount scope_w[loc] = self.space.newtuple(starargs_w) elif avail > co_argcount: - for i in range(co_argcount, co_argcount + co_kwonlyargcount): - if scope_w[i] is None: - kwonly_given += 1 too_many_args = True # if a **kwargs argument is needed, create the dict @@ -250,16 +246,13 @@ else: raise ArgErrUnknownKwds(self.space, num_remainingkwds, keywords, kwds_mapping, self.keyword_names_w) - if too_many_args: - raise ArgErrTooMany(signature.num_argnames(), - 0 if defaults_w is None else len(defaults_w), - avail, kwonly_given) # check for missing arguments and fill them from the kwds, # or with defaults, if available missing_positional = [] missing_kwonly = [] - if input_argcount < co_argcount + co_kwonlyargcount: + more_filling = (input_argcount < co_argcount + co_kwonlyargcount) + if more_filling: def_first = co_argcount - (0 if defaults_w is None else len(defaults_w)) j = 0 kwds_index = -1 @@ -271,6 +264,16 @@ if kwds_index >= 0: scope_w[i] = keywords_w[kwds_index] + if too_many_args: + kwonly_given = 0 + for i in range(co_argcount, co_argcount + co_kwonlyargcount): + if scope_w[i] is not None: + kwonly_given += 1 + raise ArgErrTooMany(signature.num_argnames(), + 0 if defaults_w is None else len(defaults_w), + avail, kwonly_given) + + if more_filling: # then, fill the normal arguments with defaults_w (if needed) for i in range(input_argcount, co_argcount): if scope_w[i] is not None: diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py --- a/pypy/interpreter/test/test_argument.py +++ b/pypy/interpreter/test/test_argument.py @@ -634,6 +634,62 @@ else: assert 0, "did not raise" + def test_dont_count_default_arguments(self): + space = self.space + msg = space.unwrap(space.appexec([], """(): + def f1(*, c): pass + try: + f1(4) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 0 positional arguments but 1 was given' + # + msg = space.unwrap(space.appexec([], """(): + def f1(*, c=8): pass + try: + f1(4) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 0 positional arguments but 1 was given' + # + msg = space.unwrap(space.appexec([], """(): + def f1(a, b, *, c): pass + try: + f1(4, 5, 6) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 2 positional arguments but 3 were given' + # + msg = space.unwrap(space.appexec([], """(): + def f1(*, c): pass + try: + f1(6, c=7) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given' + # + msg = space.unwrap(space.appexec([], """(): + def f1(*, c, d=8, e=9): pass + try: + f1(6, 2, c=7, d=8) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 0 positional arguments but 2 positional arguments (and 2 keyword-only arguments) were given' + # + msg = space.unwrap(space.appexec([], """(): + def f1(*, c, d=8, e=9, **kwds): pass + try: + f1(6, 2, c=7, d=8, morestuff=9) + except TypeError as e: + return str(e) + """)) + assert msg == 'f1() takes 0 positional arguments but 2 positional arguments (and 2 keyword-only arguments) were given' + def test_unknown_keywords(self): space = DummySpace() err = ArgErrUnknownKwds(space, 1, ['a', 'b'], [0], None) diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -300,14 +300,6 @@ """Truncate a file (by file descriptor) to a specified length.""" try: os.ftruncate(fd, length) - except IOError as e: - if not objectmodel.we_are_translated(): - # Python 2.6 raises an IOError here. Let's not repeat that mistake. - w_error = space.call_function(space.w_OSError, space.wrap(e.errno), - space.wrap(e.strerror), - space.wrap(e.filename)) - raise OperationError(space.w_OSError, w_error) - raise AssertionError except OSError as e: raise wrap_oserror(space, e) @@ -2172,7 +2164,7 @@ have_functions.append("HAVE_%s" % name) if _WIN32: have_functions.append("HAVE_MS_WINDOWS") - + def get_terminal_size(space, w_fd=None): if w_fd is None: fd = rfile.RFile(rfile.c_stdout(), close2=(None, None)).fileno() @@ -2199,14 +2191,14 @@ raise oefmt(space.w_OSError, "handle cannot be retrieved") elif handle == rwin32.INVALID_HANDLE_VALUE: raise rwin32.lastSavedWindowsError() - with lltype.scoped_alloc(rwin32.CONSOLE_SCREEN_BUFFER_INFO) as buffer_info: + with lltype.scoped_alloc(rwin32.CONSOLE_SCREEN_BUFFER_INFO) as buffer_info: success = rwin32.GetConsoleScreenBufferInfo(handle, buffer_info) if not success: raise rwin32.lastSavedWindowsError() w_columns = space.wrap(r_int(buffer_info.c_srWindow.c_Right) - r_int(buffer_info.c_srWindow.c_Left) + 1) w_lines = space.wrap(r_int(buffer_info.c_srWindow.c_Bottom) - r_int(buffer_info.c_srWindow.c_Top) + 1) else: - with lltype.scoped_alloc(rposix.WINSIZE) as winsize: + with lltype.scoped_alloc(rposix.WINSIZE) as winsize: failed = rposix.c_ioctl_voidp(fd, rposix.TIOCGWINSZ, winsize) if failed: raise exception_from_saved_errno(space, space.w_OSError) diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -198,17 +198,17 @@ def _start_from_tuple(self, space, w_tuple): - from pypy.objspace.std.tupleobject import W_TupleObject + from pypy.objspace.std.tupleobject import W_AbstractTupleObject start = 0 view = self.buf length = space.len_w(w_tuple) dim = view.getndim() dim = 0 - assert isinstance(w_tuple, W_TupleObject) + assert isinstance(w_tuple, W_AbstractTupleObject) while dim < length: w_obj = w_tuple.getitem(space, dim) - index = w_obj.int_w(space) + index = space.getindex_w(w_obj, space.w_IndexError) start = self.lookup_dimension(space, start, dim, index) dim += 1 return start @@ -292,7 +292,7 @@ itemsize = self.getitemsize() dim = 0 self.buf = SubBuffer(self.buf, strides[dim] * (start//itemsize), size*step) - shape[dim] = size + shape[dim] = size//itemsize strides[dim] = strides[dim] * step self.strides = strides self.shape = shape diff --git a/pypy/objspace/std/test/test_memoryobject.py b/pypy/objspace/std/test/test_memoryobject.py --- a/pypy/objspace/std/test/test_memoryobject.py +++ b/pypy/objspace/std/test/test_memoryobject.py @@ -168,6 +168,11 @@ slice = m[2:8] assert slice.format == 'i' assert slice.itemsize == 4 + assert slice.ndim == 1 + assert slice.readonly is False + assert slice.shape == (6,) + assert slice.strides == (4,) + assert slice.suboffsets == () assert len(slice) == 6 assert len(slice.tobytes()) == 24 assert slice.nbytes == 24 @@ -330,7 +335,8 @@ assert view[-1,-1] == 11 assert view[-3,-4] == 0 - raises(IndexError, "view.__getitem__((2**63-1,0))") + raises(IndexError, "view.__getitem__((2**31-1, 0))") + raises(IndexError, "view.__getitem__((2**63+1, 0))") raises(TypeError, "view.__getitem__((0, 0, 0))") def test_tuple_indexing_int(self): diff --git a/pypy/objspace/std/test/test_smalllongobject.py b/pypy/objspace/std/test/test_smalllongobject.py --- a/pypy/objspace/std/test/test_smalllongobject.py +++ b/pypy/objspace/std/test/test_smalllongobject.py @@ -49,9 +49,10 @@ def setup_class(cls): from pypy.interpreter import gateway - from pypy.objspace.std.smalllongobject import W_SmallLongObject def w__long(space, w_obj): - return W_SmallLongObject.frombigint(space.bigint_w(w_obj)) + assert space.config.objspace.std.withsmalllong + b = space.bigint_w(w_obj) + return space.wraplong(b.tolong()) cls.w__long = cls.space.wrap(gateway.interp2app(w__long)) def test_sl_simple(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit