classification
Title: Improve syntax errors for invalid if expressions
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: aroberge, miguendes, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2021-07-31 11:25 by miguendes, last changed 2021-08-02 19:05 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27506 merged miguendes, 2021-07-31 11:28
PR 27565 merged miss-islington, 2021-08-02 17:11
Messages (3)
msg398633 - (view) Author: Miguel Brito (miguendes) * Date: 2021-07-31 11:25
Hi, I was playing around with Python's grammar and noticed that the error message for if expression is generic, so not very informative.

I decided to improve it slightly.

*From*:

```
>>> a = 42 if True
  File "<stdin>", line 1
    a = 42 if True
                  ^
SyntaxError: invalid syntax
```

*To*:

```
$ ./python
Python 3.10.0b4 (tags/v3.10.0b4-dirty:2ba4b20854, Jul 31 2021, 11:50:15) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 42 if True
  File "<stdin>", line 1
    a = 42 if True
                  ^
SyntaxError: invalid syntax. Conditional expression expected an 'else' here.
```
msg398787 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-02 17:11
New changeset 28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332 by Miguel Brito in branch 'main':
bpo-44792: Improve syntax errors for if expressions (GH-27506)
https://github.com/python/cpython/commit/28b6dc9dd5d1ce6f8aff7e06d4ef9afdc2bc8332
msg398799 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-02 19:05
New changeset 567176249ea95c074eb80199aaf19f3a55aa3954 by Miss Islington (bot) in branch '3.10':
bpo-44792: Improve syntax errors for if expressions (GH-27506) (GH-27565)
https://github.com/python/cpython/commit/567176249ea95c074eb80199aaf19f3a55aa3954
History
Date User Action Args
2021-08-02 19:05:43pablogsalsetmessages: + msg398799
2021-08-02 19:05:42pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-08-02 17:11:46miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26072
2021-08-02 17:11:44pablogsalsetnosy: + pablogsal
messages: + msg398787
2021-07-31 18:09:40arobergesetnosy: + aroberge
2021-07-31 11:28:10miguendessetkeywords: + patch
stage: patch review
pull_requests: + pull_request26020
2021-07-31 11:25:20miguendescreate