◐ Shell
reader mode source ↗
Skip to content

bpo-40334: Do not show error caret if RAISE_SYNTAX_ERROR_NO_COL_OFFSE…#20020

Closed
pablogsal wants to merge 1 commit into
python:masterfrom
pablogsal:no-col-offset
Closed

bpo-40334: Do not show error caret if RAISE_SYNTAX_ERROR_NO_COL_OFFSE…#20020
pablogsal wants to merge 1 commit into
python:masterfrom
pablogsal:no-col-offset

Conversation

@pablogsal

@pablogsal pablogsal commented May 10, 2020

Copy link
Copy Markdown
Member

Before:

>>> f(x for x in range(10),)
  File "<console>", line 1
    f(x for x in range(10),)
    ^
SyntaxError: Generator expression must be parenthesized

With this PR:

>>> f(x for x in range(10),)
  File "<console>", line 1
SyntaxError: Generator expression must be parenthesized

https://bugs.python.org/issue40334

@pablogsal

pablogsal commented May 10, 2020

Copy link
Copy Markdown
Member Author

Wow, I am confused about this failing test in test_cmd_line_script:

     def test_syntaxerror_unindented_caret_position(self):
         script = "1 + 1 = 2\n"
         with support.temp_dir() as script_dir:
             script_name = _make_test_script(script_dir, 'script', script)
             exitcode, stdout, stderr = assert_python_failure(script_name)
             text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
             # Confirm that the caret is located under the first 1 character
             self.assertIn("\n    1 + 1 = 2\n    ^", text)

that expects that the caret is on the first character but the error in invalid_assignment is using RAISE_SYNTAX_ERROR_NO_COL_OFFSET. @lysnikolaou Does RAISE_SYNTAX_ERROR_NO_COL_OFFSET means "put the column offset to the beginning" then? If so, I find that somewhat confusing.

@gvanrossum

Copy link
Copy Markdown
Member

Wow, I am confused about this failing test in test_cmd_line_script:

That's a bug. The old parser puts the caret at the start of the "target". Example:

  File "/Users/guido/cpython/@.py", line 2
    if a: 1 + 1 = 2
          ^
SyntaxError: cannot assign to operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants