Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r97373:c0b2526268ab
Date: 2019-09-03 22:00 +0200
http://bitbucket.org/pypy/pypy/changeset/c0b2526268ab/
Log: more print error message work, this one requiring a change to
descroperation (in CPython it's done in abstract.c)
diff --git a/pypy/module/exceptions/test/test_exc.py
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -471,6 +471,14 @@
check("print 1 1",
"Missing parentheses in call to 'print'")
+ def test_print_and_operators(self):
+ with raises(TypeError) as excinfo:
+ print >> 1, 5
+ assert 'Did you mean "print(<message>, file=<output_stream>)"?' in
str(excinfo.value)
+ with raises(TypeError) as excinfo:
+ print -1
+ assert 'Did you mean "print(<-number>)"?' in str(excinfo.value)
+
def test_importerror_kwarg_error(self):
msg = "'invalid' is an invalid keyword argument for this function"
exc = raises(TypeError,
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -506,6 +506,10 @@
return w_res
return None
+class PrintCache(object):
+ def __init__(self, space):
+ self.w_print = space.getattr(space.builtin, space.newtext("print"))
+
# regular methods def helpers
@@ -515,6 +519,12 @@
symbol.replace('%', '%%'),)
seq_bug_compat = (symbol == '+' or symbol == '*')
+ printerrormsg = None
+ if symbol == ">>":
+ printerrormsg = errormsg + '. Did you mean "print(<message>,
file=<output_stream>)"?'
+ if symbol == "-":
+ printerrormsg = errormsg + '. Did you mean "print(<-number>)"?'
+
def binop_impl(space, w_obj1, w_obj2):
w_typ1 = space.type(w_obj1)
w_typ2 = space.type(w_obj2)
@@ -549,6 +559,8 @@
w_res = _invoke_binop(space, w_right_impl, w_obj2, w_obj1)
if w_res is not None:
return w_res
+ if printerrormsg is not None and w_obj1 is
space.fromcache(PrintCache).w_print:
+ raise oefmt(space.w_TypeError, printerrormsg, w_typ1, w_typ2)
raise oefmt(space.w_TypeError, errormsg, w_typ1, w_typ2)
return func_with_new_name(binop_impl, "binop_%s_impl"%left.strip('_'))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit