This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients corona10, piyushhajare, xtreak
Date 2018-07-01.13:33:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530452023.4.0.56676864532.issue34013@psf.upfronthosting.co.za>
In-reply-to
Content
I took an initial stab at this and there is a comment where if there is an open paren then to use the normal error message. Additional context on the issue which lists false positive cases where the change was introduced https://bugs.python.org/issue21669. I removed the check where the left paren count is not -1 in case of a function call and it seems to work. Of course, there are cases to handle as mentioned in the linked issue and I tried some of the cases like "foo".toupper().tolower() and the results as below : 

Patch : 

diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index bb50c1c..7e616cf 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -2966,10 +2966,7 @@ _report_missing_parentheses(PySyntaxErrorObject *self)
     if (left_paren_index < -1) {
         return -1;
     }
-    if (left_paren_index != -1) {
-        /* Use default error message for any line with an opening paren */
-        return 0;
-    }
+
     /* Handle the simple statement case */
     legacy_check_result = _check_for_legacy_statements(self, 0);
     if (legacy_check_result < 0) {

Cases :

➜  cpython git:(master) ✗ cat foo_print.py
class Foo:
    pass

print Foo().header(a=foo(1))
➜  cpython git:(master) ✗ ./python foo_print.py
  File "foo_print.py", line 4
    print Foo().header(a=foo(1))
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(Foo().header(a=foo(1)))?

➜  cpython git:(master) ✗ cat foo_print.py
print "a".toupper().tolower()
➜  cpython git:(master) ✗ ./python foo_print.py
  File "foo_print.py", line 1
    print "a".toupper().tolower()
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("a".toupper().tolower())?


Linked cases in the patch : 

➜  cpython git:(master) ✗ cat foo_print.py
print (foo.)
➜  cpython git:(master) ✗ ./python foo_print.py
  File "foo_print.py", line 1
    print (foo.)
               ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print((foo.))?


Would like to link to https://hackmd.io/s/ByMHBMjFe#08-Debugging-Python-Objects . As a beginner the tutorial was helpful and I had to set a break point on Objects/exceptions.c:1323 where SyntaxError_init is called and then execute line by line where the current code returns the left_paren_index which you can set as `set left_paren_index = -1` to skip the branch and then continue the program to print the above error messages. IMO I think it was an explicit decision with this change being done 4 years ago with the false positive cases and tests listed but I am curious if there are any improvements in this area to be done.


Thanks
History
Date User Action Args
2018-07-01 13:33:43xtreaksetrecipients: + xtreak, corona10, piyushhajare
2018-07-01 13:33:43xtreaksetmessageid: <1530452023.4.0.56676864532.issue34013@psf.upfronthosting.co.za>
2018-07-01 13:33:43xtreaklinkissue34013 messages
2018-07-01 13:33:43xtreakcreate