Skip to content

Improve error message for unterminated strings with escapes #100445

Closed
@hauntsaninja

Description

@hauntsaninja

Inspired by #55688 and #94768.

Currently, this code raises the following error:

>>> "asdf\"
  File "<stdin>", line 1
    "asdf\"
    ^
SyntaxError: unterminated string literal (detected at line 1)

Maybe there's room to make this error message more helpful, to make the source of the error more obvious for users unfamiliar with escapes. Could the following be better?

>>> "asdf\"
  File "<stdin>", line 1
    "asdf\"
    ^
SyntaxError: unterminated string literal (detected at line 1); perhaps you escaped the end quote?

(The raw string situation in the linked issues that inspired this is a little extra tricky, since the workaround is still not clear. But hopefully the message still makes it clearer to users what is going on)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions