https://github.com/python/cpython/commit/9375b9ca3a4998678ba74ff5c77ed540a4dcf887
commit: 9375b9ca3a4998678ba74ff5c77ed540a4dcf887
branch: main
author: Victor Stinner <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-08-12T04:12:14Z
summary:

Remove "print >>obj" exception hint for Python 2 (#122853)

files:
M Lib/test/test_print.py
M Objects/abstract.c

diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py
index 5f1bfd9e30db98..f4805a1d6c6602 100644
--- a/Lib/test/test_print.py
+++ b/Lib/test/test_print.py
@@ -188,38 +188,6 @@ def test_string_in_loop_on_same_line(self):
         self.assertIn("Missing parentheses in call to 'print'. Did you mean 
print(...)",
                 str(context.exception))
 
-    def test_stream_redirection_hint_for_py2_migration(self):
-        # Test correct hint produced for Py2 redirection syntax
-        with self.assertRaises(TypeError) as context:
-            print >> sys.stderr, "message"
-        self.assertIn('Did you mean "print(<message>, '
-                'file=<output_stream>)"?', str(context.exception))
-
-        # Test correct hint is produced in the case where RHS implements
-        # __rrshift__ but returns NotImplemented
-        with self.assertRaises(TypeError) as context:
-            print >> 42
-        self.assertIn('Did you mean "print(<message>, '
-                'file=<output_stream>)"?', str(context.exception))
-
-        # Test stream redirection hint is specific to print
-        with self.assertRaises(TypeError) as context:
-            max >> sys.stderr
-        self.assertNotIn('Did you mean ', str(context.exception))
-
-        # Test stream redirection hint is specific to rshift
-        with self.assertRaises(TypeError) as context:
-            print << sys.stderr
-        self.assertNotIn('Did you mean', str(context.exception))
-
-        # Ensure right operand implementing rrshift still works
-        class OverrideRRShift:
-            def __rrshift__(self, lhs):
-                return 42 # Force result independent of LHS
-
-        self.assertEqual(print >> OverrideRRShift(), 42)
-
-
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 8626584e9bf56c..7cca81464cd112 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1000,20 +1000,6 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, 
const char *op_name)
     PyObject *result = BINARY_OP1(v, w, op_slot, op_name);
     if (result == Py_NotImplemented) {
         Py_DECREF(result);
-
-        if (op_slot == NB_SLOT(nb_rshift) &&
-            PyCFunction_CheckExact(v) &&
-            strcmp(((PyCFunctionObject *)v)->m_ml->ml_name, "print") == 0)
-        {
-            PyErr_Format(PyExc_TypeError,
-                "unsupported operand type(s) for %.100s: "
-                "'%.100s' and '%.100s'. Did you mean \"print(<message>, "
-                "file=<output_stream>)\"?",
-                op_name,
-                Py_TYPE(v)->tp_name,
-                Py_TYPE(w)->tp_name);
-            return NULL;
-        }
         return binop_type_error(v, w, op_name);
     }
     return result;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to