Why is an IndentationError being raised here rather than a SyntaxError?

Viewed 242

Why in the following program is an IndentationError being raised rather than SyntaxError?

>>> if True:
... print "just right!"
  File "<stdin>", line 2
    print "just right!"
        ^
IndentationError: Missing parentheses in call to 'print'

To make sure the IDLE wasn't just acting funny, I also tested this code by running it from a normal source file. The same exception type is still being raised. The versions of Python I used to test this were Python 3.5.2 and Python 3.6.1.

It is my understanding that missing parenthesis when using print was considered a SyntaxError, not an IndentationError. The top answer in the post What does “SyntaxError: Missing parentheses in call to 'print'” mean in Python? also seems to support this:

“SyntaxError: Missing parentheses in call to 'print'” is a new error message that was added in Python 3.4.2 primarily to help users that are trying to follow a Python 2 tutorial while running Python 3.

Is this a bug? If so, what's causing it?

1 Answers
Related