Skip to content

Commit 9375b9c

Browse files
authored
Remove "print >>obj" exception hint for Python 2 (#122853)
1 parent 6aa35f3 commit 9375b9c

File tree

2 files changed

+0
-46
lines changed

2 files changed

+0
-46
lines changed

Lib/test/test_print.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,38 +188,6 @@ def test_string_in_loop_on_same_line(self):
188188
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
189189
str(context.exception))
190190

191-
def test_stream_redirection_hint_for_py2_migration(self):
192-
# Test correct hint produced for Py2 redirection syntax
193-
with self.assertRaises(TypeError) as context:
194-
print >> sys.stderr, "message"
195-
self.assertIn('Did you mean "print(<message>, '
196-
'file=<output_stream>)"?', str(context.exception))
197-
198-
# Test correct hint is produced in the case where RHS implements
199-
# __rrshift__ but returns NotImplemented
200-
with self.assertRaises(TypeError) as context:
201-
print >> 42
202-
self.assertIn('Did you mean "print(<message>, '
203-
'file=<output_stream>)"?', str(context.exception))
204-
205-
# Test stream redirection hint is specific to print
206-
with self.assertRaises(TypeError) as context:
207-
max >> sys.stderr
208-
self.assertNotIn('Did you mean ', str(context.exception))
209-
210-
# Test stream redirection hint is specific to rshift
211-
with self.assertRaises(TypeError) as context:
212-
print << sys.stderr
213-
self.assertNotIn('Did you mean', str(context.exception))
214-
215-
# Ensure right operand implementing rrshift still works
216-
class OverrideRRShift:
217-
def __rrshift__(self, lhs):
218-
return 42 # Force result independent of LHS
219-
220-
self.assertEqual(print >> OverrideRRShift(), 42)
221-
222-
223191

224192
if __name__ == "__main__":
225193
unittest.main()

Objects/abstract.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,20 +1000,6 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name)
10001000
PyObject *result = BINARY_OP1(v, w, op_slot, op_name);
10011001
if (result == Py_NotImplemented) {
10021002
Py_DECREF(result);
1003-
1004-
if (op_slot == NB_SLOT(nb_rshift) &&
1005-
PyCFunction_CheckExact(v) &&
1006-
strcmp(((PyCFunctionObject *)v)->m_ml->ml_name, "print") == 0)
1007-
{
1008-
PyErr_Format(PyExc_TypeError,
1009-
"unsupported operand type(s) for %.100s: "
1010-
"'%.100s' and '%.100s'. Did you mean \"print(<message>, "
1011-
"file=<output_stream>)\"?",
1012-
op_name,
1013-
Py_TYPE(v)->tp_name,
1014-
Py_TYPE(w)->tp_name);
1015-
return NULL;
1016-
}
10171003
return binop_type_error(v, w, op_name);
10181004
}
10191005
return result;

0 commit comments

Comments
 (0)