[pypy-svn] pypy default: Test the error message for 'f(**42)', and improve and test
arigo
commits-noreply at bitbucket.org
Mon Feb 7 22:54:06 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41689:2bbf38842bd1
Date: 2011-02-07 22:52 +0100
http://bitbucket.org/pypy/pypy/changeset/2bbf38842bd1/
Log: Test the error message for 'f(**42)', and improve and test the error
message for 'f(*42)'.
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -147,8 +147,19 @@
def _combine_starargs_wrapped(self, w_stararg):
# unpack the * arguments
- self.arguments_w = (self.arguments_w +
- self.space.fixedview(w_stararg))
+ space = self.space
+ try:
+ args_w = space.fixedview(w_stararg)
+ except OperationError, e:
+ if e.match(space, space.w_TypeError):
+ w_type = space.type(w_stararg)
+ typename = w_type.getname(space)
+ raise OperationError(
+ space.w_TypeError,
+ space.wrap("argument after * must be "
+ "a sequence, not %s" % (typename,)))
+ raise
+ self.arguments_w = self.arguments_w + args_w
def _combine_starstarargs_wrapped(self, w_starstararg):
# unpack the ** arguments
@@ -163,7 +174,7 @@
except OperationError, e:
if e.match(space, space.w_AttributeError):
w_type = space.type(w_starstararg)
- typename = w_type.getname(space, '?')
+ typename = w_type.getname(space)
raise OperationError(
space.w_TypeError,
space.wrap("argument after ** must be "
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
@@ -117,7 +117,7 @@
def type(self, obj):
class Type:
- def getname(self, space, default):
+ def getname(self, space, default='?'):
return type(obj).__name__
return Type()
@@ -500,6 +500,22 @@
s = err.getmsg('foo')
assert s == "foo() takes exactly 1 argument (3 given)"
+ def test_bad_type_for_star(self):
+ space = self.space
+ try:
+ Arguments(space, [], w_stararg=space.wrap(42))
+ except OperationError, e:
+ msg = space.str_w(space.str(e.get_w_value(space)))
+ assert msg == "argument after * must be a sequence, not int"
+ else:
+ assert 0, "did not raise"
+ try:
+ Arguments(space, [], w_starstararg=space.wrap(42))
+ except OperationError, e:
+ msg = space.str_w(space.str(e.get_w_value(space)))
+ assert msg == "argument after ** must be a mapping, not int"
+ else:
+ assert 0, "did not raise"
def test_unknown_keywords(self):
err = ArgErrUnknownKwds(1, ['a', 'b'], [True, False])
More information about the Pypy-commit
mailing list