msg300486 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-18 11:07 |
https://bugs.python.org/issue30721 introduces a new custom error message, such that in 3.7+ "print >> sys.stderr" will report: ``` >>> import sys >>> print >> sys.stderr Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'. Did you mean "print(, file=<output_stream>)"? ``` This is quite clearly an enhancement to the error reporting rather than a bug fix, but similar to the syntax errors for print statements without parentheses, it's an enhancement that only touches an error handling code path (specifically, the one where >> is already in the process of raising TypeError after operand coercion failed), and relates to an issue that a lot of ad hoc Python scripts are likely to encounter. As such, before I propose it as a downstream patch for Fedora's Python 3.6 stack, I figured I'd propose it as an upstream maintenance backport first. |
|
|
msg300494 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2017-08-18 12:59 |
I'm in favor of backporting to 3.6. It's not an intrusive change and is helpful in porting 2.x scripts. |
|
|
msg300498 - (view) |
Author: Ned Deily (ned.deily) *  |
Date: 2017-08-18 14:21 |
I am OK with adding it to 3.6.x. |
|
|
msg300521 - (view) |
Author: Barry A. Warsaw (barry) *  |
Date: 2017-08-18 17:28 |
It's probably fine, since it should be a rare occurrence, but it of course has the potential to break things like tests (doc and otherwise). Unlikely, but it should be pointed out. Still, I'm also fine with backporting it. |
|
|
msg300523 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2017-08-18 18:34 |
But this backport would break my code: >>> print = 10 >>> print >> 1 5 Just kidding ;-) +1 for the backport. It will likely save some headaches. |
|
|
msg300525 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-08-18 18:43 |
It will not break this code. The only visible effect is changing error messages of some TypeError exceptions. |
|
|
msg300566 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-19 06:04 |
The condition we (mostly Serhiy) came up with for the check is actually kinda neat, since it's based on the value of the LHS and is hard to trigger accidentally: ``` >>> printf = print >>> print = 10 >>> print >> 1 5 >>> printf >> 1 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and 'int'. Did you mean "print(, file=<output_stream>)" ``` Anyway, I'll put together a PR that combines both the original patch and the follow up fix to add the missing question mark. |
|
|
msg300568 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-19 06:59 |
New changeset 1a05e87ec75436d818f05a5dabcecaea67334cbd by Nick Coghlan in branch '3.6': [3.6] bpo-31232: Backport custom print rshift message (GH-3155) https://github.com/python/cpython/commit/1a05e87ec75436d818f05a5dabcecaea67334cbd |
|
|
msg300570 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-19 07:00 |
Thanks all! |
|
|