msg296518 - (view) |
Author: Sanyam Khurana (CuriousLearner) *  |
Date: 2017-06-21 05:13 |
While working on issue: http://bugs.python.org/issue30597 to enhance the custom error message by showing expected output in Python3 syntax when someone uses Python2 syntax, a PR was raised: https://github.com/python/cpython/pull/2009, where we just handled the case for print with soft-space and excessive white-space. In the implementation discussion, an issue was raised to handle the case with right shift operator by Nick as in here: http://bugs.python.org/issue30597#msg295484 Nick suggested here about the possible patch: https://github.com/python/cpython/pull/2009#issuecomment-307539241 |
|
|
msg296525 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-06-21 06:43 |
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 "", line 1, in 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(, 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. |
|
|
msg299128 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2017-07-25 18:05 |
The test added in the PR passes on linux (Travis) and Mac (op's machine), fails on Windows (Appveyor). The patch itself modifies abstract.c. Could some Windows expert take a look? test_string_with_stream_redirection (test.test_print.TestPy2MigrationHint) ... FAIL FAIL: test_string_with_stream_redirection (test.test_print.TestPy2MigrationHint) Traceback (most recent call last): File "C:\projects\cpython\lib\test\test_print.py", line 165, in test_string_with_stream_redirection 'file=<output_stream>)', str(context.exception)) AssertionError: 'Did you mean "print(, file=<output_stream>)' not found in "unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.StringIO'" |
|
|
msg299139 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2017-07-25 21:06 |
The "op_slot == 96" looks suspicious - how is this value actually supposed to be calculated? |
|
|
msg299238 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-07-26 14:56 |
Checking how we do it elsewhere, `NB_SLOT(nb_rshift)` looks like the right replacement. That's a compiler-dependent struct field offset calculation, so a discrepancy there could easily be the cause of a Windows-only failure. |
|
|
msg300484 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-08-18 10:37 |
New changeset 5e2eb35bbed3e84079165e576cdb50ef36e13493 by Serhiy Storchaka (Sanyam Khurana) in branch 'master': bpo-30721: Show correct syntax hint in Py3 when using Py2 redirection syntax (#2345) https://github.com/python/cpython/commit/5e2eb35bbed3e84079165e576cdb50ef36e13493 |
|
|
msg300485 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-18 11:00 |
Checking the merged implementation locally, I belatedly noticed that we forgot the trailing question mark on the question: ``` >>> 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>)" ``` So putting this back to "needs patch" (no NEWS entry needed, just the missing question marks in the patch and the tests). |
|
|
msg300487 - (view) |
Author: Sanyam Khurana (CuriousLearner) *  |
Date: 2017-08-18 11:08 |
Ah, sorry for that. I'll just fix that right away in a few mins :) |
|
|
msg300488 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-18 11:08 |
Note that I filed a separate issue to ask Ned about potentially backporting this to 3.6: https://bugs.python.org/issue31232 |
|
|
msg300492 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-18 12:18 |
New changeset a7c449b8c08933deabcf329fb74ed1336f6db34f by Nick Coghlan (Sanyam Khurana) in branch 'master': bpo-30721: Add missing '?' to new error message (GH-3131) https://github.com/python/cpython/commit/a7c449b8c08933deabcf329fb74ed1336f6db34f |
|
|
msg300493 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2017-08-18 12:19 |
And done - thanks folks! |
|
|
msg300569 - (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 |
|
|