Author: Carl Friedrich Bolz <[email protected]>
Branch: better-error-missing-self
Changeset: r87560:fd909a45fb0b
Date: 2016-10-04 08:42 +0200
http://bitbucket.org/pypy/pypy/changeset/fd909a45fb0b/
Log: in the simplest cases, produce the error message also for bound
methods
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1133,6 +1133,7 @@
# reuse callable stack place for w_inst
frame.settopvalue(w_inst, nargs)
nargs += 1
+ methodcall = True
elif nargs > 0 and (
self.abstract_isinstance_w(frame.peekvalue(nargs-1), #
:-(
w_func.w_class)):
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
@@ -742,13 +742,28 @@
def f0():
pass
exc = raises(TypeError, f0, 1)
+ # does not contain the warning about missing self
assert exc.value.message == "f0() takes no arguments (1 given)"
def test_error_message_module_function(self):
import operator # use repeat because it's defined at applevel
exc = raises(TypeError, lambda : operator.repeat(1, 2, 3))
+ # does not contain the warning about missing self
assert exc.value.message == "repeat() takes exactly 2 arguments (3
given)"
+ def test_error_message_bound_method(self):
+ class A(object):
+ def f0():
+ pass
+ def f1(a):
+ pass
+ m0 = A().f0
+ exc = raises(TypeError, lambda : m0())
+ assert exc.value.message == "f0() takes no arguments (1 given). Did
you forget 'self' in the function definition?"
+ m1 = A().f1
+ exc = raises(TypeError, lambda : m1(1))
+ assert exc.value.message == "f1() takes exactly 1 argument (2 given).
Did you forget 'self' in the function definition?"
+
def test_unicode_keywords(self):
def f(**kwargs):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit