Author ncoghlan
Recipients CuriousLearner, cheryl.sabella, ncoghlan, serhiy.storchaka, storymode7
Date 2018-01-27.13:20:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Re-reading the code for _set_legacy_print_statement_msg, I noticed that we're not currently taking the "start" parameter into account, and that's the offset the compiler passes in to tell us where on the line it found the text "print ". Oops :)

We're also currently going to mishandle code like "x = 1; print x; pass" as well: the suggestion for that is "print(x)", but we would currently suggest "print(print x; pass)".

Fixing the left offset shouldn't be too difficult, as I believe the correct value for that is just "PRINT_OFFSET + start".

For the right offset, I think we'll want to drop the initial XStrip call added for bpo-32028 entirely, and instead calculate the right offset as a PyUnicode_FindChar search for ";" (replacing it with the length of the input string if the separator isn't found).

Any trailing whitespace (either before the ";", if one is present, or before the end of the line otherwise) will then be stripped by the remaining XStrip call (the one after the PyUnicode_Substring call).

(Even with those improvements, there will still be cases where the heuristic gives an incorrect suggestion due to a syntax error within the expression to be displayed, like "print value:", but there isn't anything simple we can do about those short of trying to compile the calculated suggestion, and I'm not prepared to go that far yet)
Date User Action Args
2018-01-27 13:20:04ncoghlansetrecipients: + ncoghlan, serhiy.storchaka, CuriousLearner, cheryl.sabella, storymode7
2018-01-27 13:20:04ncoghlansetmessageid: <>
2018-01-27 13:20:04ncoghlanlinkissue32685 messages
2018-01-27 13:20:04ncoghlancreate