GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve syntax error for wrongly closed strings · Issue #88535 · python/cpython

Improve syntax error for wrongly closed strings #88535

New issue
Copy link
New issue
Copy link
Closed
Closed
Improve syntax error for wrongly closed strings#88535
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@pablogsal
pablogsal
opened on Jun 9, 2021
Issue body actions
BPO 44369
Nosy @aroberge, @lysnikolaou, @pablogsal, @isidentical
PRs
  • gh-88535: Improve syntax error for wrongly closed strings #26633
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-06-09.21:15:52.840>
    labels = ['interpreter-core', '3.10', '3.11']
    title = 'Improve syntax error for wrongly closed strings'
    updated_at = <Date 2021-06-14.18:54:32.243>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-06-14.18:54:32.243>
    actor = 'pablogsal'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Parser']
    creation = <Date 2021-06-09.21:15:52.840>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44369
    keywords = ['patch']
    message_count = 4.0
    messages = ['395476', '395491', '395696', '395837']
    nosy_count = 4.0
    nosy_names = ['aroberge', 'lys.nikolaou', 'pablogsal', 'BTaskaya']
    pr_nums = ['26633']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44369'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. pablogsal commented on Jun 9, 2021

      @pablogsal
      pablogsal
      on Jun 9, 2021
      MemberAuthor
      More actions

      Let's asume this string:
      "
      x = "Cannot recover from "MemoryErrors" while something happnes while "

      The line is incorrect because the quotes arround MemoryErrors are the same as the string is used, resulting in STRING + expression + STRING.

      Currenly we say:

      >>> 'Cannot recover from 'MemoryErrors' while '
        File "<stdin>", line 1
          'Cannot recover from 'MemoryErrors' while '
                                ^
      SyntaxError: invalid syntax

      but I think it will be a great improvement if we say:

      >>> 'Cannot recover from 'MemoryErrors' while '
        File "<stdin>", line 1
          'Cannot recover from 'MemoryErrors' while '
                                ^^^^^^^^^^^^
      SyntaxError: invalid syntax. Did you use the same quotes here as the string?

      Probably the message should be better, but I think this is a good improvement.

    2. pablogsal
      added
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      on Jun 9, 2021
    3. aroberge commented on Jun 9, 2021

      @aroberge
      arobergemannequin
      on Jun 9, 2021
      Mannequin
      More actions

      I like this. While it would be a bit longer, I'm wondering if the message should not read instead as follows:

      ... Did you use the same quotes here as those enclosing the string?

      ===

      I suspect that errors coming from the use of a single quote, as in:

      'Don't do this'

      might be just as prevalent if not more so; however, they might be more difficult to properly diagnose.

    4. isidentical commented on Jun 12, 2021

      @isidentical
      isidentical
      on Jun 12, 2021
      SponsorMember
      More actions

      From what I can share by my experience, this error happens soo much. So I'd love to see it.

      For a more consistent message with others, maybe it could be something like this;

      SyntaxError: invalid syntax. Maybe you meant to use a different type of quote

    5. pablogsal commented on Jun 14, 2021

      @pablogsal
      pablogsal
      on Jun 14, 2021
      MemberAuthor
      More actions

      One problem with that is that the lookahead will move the error indicator to some incorrect place if the match fails. For example:

      PYTHON3.9

      >>> "dfssdfsdfsd" fdsf sdfsdfsd {}
        File "<stdin>", line 1
          "dfssdfsdfsd" fdsf sdfsdfsd {}
                        ^
      SyntaxError: invalid syntax
      with this PR:
      >>> "dfssdfsdfsd" fdsf sdfsdfsd {}
        File "<stdin>", line 1
          "dfssdfsdfsd" fdsf sdfsdfsd {}
                                      ^
      SyntaxError: invalid syntax

      We need a solution to this problem first

    6. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    7. erlend-aasland
      added
      type-featureA feature request or enhancementA feature request or enhancement
      and removed
      3.11only security fixesonly security fixes
      3.10 (EOL)end of lifeend of life
      on Mar 27, 2024
    8. pablogsal
      added a commit that references this issue on Feb 13, 2025

      gh-88535: Improve syntax error for wrongly closed strings (#26633)

      6fb5138
    9. adorilson commented on Jun 25, 2025

      @adorilson
      adorilson
      on Jun 25, 2025
      Contributor
      More actions

      Could this be closed? It is in whatsnew 3.14.

    10. pablogsal
      closed this as completedon Jun 25, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402520 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.