This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Improve error messages for non-matching `elif`/`else` statements
Type: behavior Stage: patch review
Components: Parser Versions: Python 3.11, Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, Crowthebird, aroberge, lys.nikolaou, pablogsal
Priority: normal Keywords: patch

Created on 2021-11-08 23:51 by Crowthebird, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 29481 closed Crowthebird, 2021-11-09 00:05
PR 29513 open Crowthebird, 2021-11-10 10:38
PR 29775 open Crowthebird, 2021-11-25 12:15
Messages (2)
msg405990 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-08 23:51
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.
msg405997 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-09 04:28
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.
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89920
2021-11-25 12:15:15Crowthebirdsetpull_requests: + pull_request28012
2021-11-10 10:38:15Crowthebirdsetpull_requests: + pull_request27765
2021-11-09 11:29:11arobergesetnosy: + aroberge
2021-11-09 09:22:30AlexWaygoodsettitle: non-matching `elif`/`else` statements with uninformative errors -> Improve error messages for non-matching `elif`/`else` statements
2021-11-09 09:20:59AlexWaygoodsetnosy: + AlexWaygood
2021-11-09 04:28:31Crowthebirdsetmessages: + msg405997
title: `elif` inside `if` block is a `SyntaxError` -> non-matching `elif`/`else` statements with uninformative errors
2021-11-09 00:05:41Crowthebirdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27732
2021-11-08 23:51:38Crowthebirdcreate