Skip to content

Improve error messages for non-matching elif/else statements #89920

Open

Description

@thatbirdguythatuknownot
BPO 45759
Nosy @aroberge, @lysnikolaou, @pablogsal, @AlexWaygood, @thatbirdguythatuknownot
PRs
  • bpo-45759: Better error messages for non-matching 'elif'/'else' state… #29481
  • bpo-45759: Better error messages for non-matching 'elif'/'else' statements #29513
  • bpo-45759: Re: Better error messages for non-matching 'elif'/'else' statements #29775
  • 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-11-08.23:51:38.287>
    labels = ['interpreter-core', 'type-bug', '3.10', '3.11']
    title = 'Improve error messages for non-matching `elif`/`else` statements'
    updated_at = <Date 2021-11-25.12:15:15.681>
    user = 'https://github.com/thatbirdguythatuknownot'

    bugs.python.org fields:

    activity = <Date 2021-11-25.12:15:15.681>
    actor = 'Crowthebird'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Parser']
    creation = <Date 2021-11-08.23:51:38.287>
    creator = 'Crowthebird'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45759
    keywords = ['patch']
    message_count = 2.0
    messages = ['405990', '405997']
    nosy_count = 5.0
    nosy_names = ['aroberge', 'lys.nikolaou', 'pablogsal', 'AlexWaygood', 'Crowthebird']
    pr_nums = ['29481', '29513', '29775']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45759'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. thatbirdguythatuknownot commented on Nov 8, 2021

      thatbirdguythatuknownotmannequin
      MannequinAuthor

      While fixing errors in a program, I encountered this:

      if a == b + 2:
          c = sqrt(b) + a**2
          elif a == b + 3:
          ^^^^
      SyntaxError: Invalid syntax

      It should be giving an IndentationError or a better error message at least.

    2. thatbirdguythatuknownot commented on Nov 9, 2021

      thatbirdguythatuknownotmannequin
      MannequinAuthor

      I'd like to expand this to more than just elif/else statements inside if` statement blocks and make an error for other cases as well. I currently have a PR that has a general error to accommodate those cases.

    3. changed the title [-]`elif` inside `if` block is a `SyntaxError`[/-] [+]non-matching `elif`/`else` statements with uninformative errors[/+] on Nov 9, 2021
    4. changed the title [-]non-matching `elif`/`else` statements with uninformative errors[/-] [+]Improve error messages for non-matching `elif`/`else` statements[/+] on Nov 9, 2021
    5. transferred this issue fromon Apr 10, 2022
    6. added
      type-featureA feature request or enhancement
      3.12only security fixes
      and removed
      type-bugAn unexpected behavior, bug, or error
      3.11only security fixes
      on Oct 7, 2022
    7. iritkatriel commented on Apr 4, 2023

      @iritkatriel
      Member
    8. erlend-aasland commented on Jan 5, 2024

      @erlend-aasland
      Contributor

      ISTM that error messages was improved in #29513. Can we close this as completed, or is there remaining actionable items?

    9. added
      pendingThe issue will be closed if no feedback is provided
      on Jan 5, 2024
    10. lysnikolaou commented on Jan 5, 2024

      @lysnikolaou
      Member

      I think we can close this, yes.

    11. removed
      pendingThe issue will be closed if no feedback is provided
      on Jan 5, 2024
    12. encukou commented on Jun 3, 2024

      @encukou
      Member

      This introduced a regression; it might need to be reverted for 3.13.0b2. See #119724

    13. encukou commented on Jun 4, 2024

      @encukou
      Member

      The commit was reverted. Re-opening in case someone wants to take another stab at this.

    14. reopened this on Jun 4, 2024
    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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions