[issue30721] Show expected input for right shift operator usage in custom "print" error message

Nick Coghlan report at bugs.python.org
Wed Jun 21 02:43:17 EDT 2017


Nick Coghlan added the comment:

The specific error in question here is the one where Python 3 reads the old Python 2 stream redirection syntax as a combination of the right shift operator and tuple creation:

```
>>> print >> sys.stderr, "message"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'
```

Searching for that error message indicates that people are hitting it reasonably frequently, so we may be able to save them a trip to Google by adding a custom 'Did you mean "print(<output>, file={:100!r})'.format(rhs)"? message when the right-shift operand dispatch is about to report the default "no implementation" type error, and the LHS is the print builtin.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30721>
_______________________________________


More information about the Python-bugs-list mailing list