Skip to content

gh-129515: Clarify syntax error messages for conditional expressions #129880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Feb 18, 2025

Conversation

sergey-miryanov
Copy link
Contributor

@sergey-miryanov sergey-miryanov commented Feb 9, 2025

Along the suggestion from the original issue, I have added the following rules and messages:
The following expressions will be handled by a=disjunction 'if' b=disjunction 'else' c=invalid_ifexp_orelse_stmt and generate the message "Syntax Error: statement given where 'orelse' expression required" instead of just "Syntax Error: invalid syntax":

1 if True else pass
1 if True else return
1 if True else raise Exception('test')
1 if True else del smth
1 if True else yield 2
1 if True else assert False
1 if True else break
1 if True else continue

The following expressions will be handled by a=invalid_ifexp_body_stmt 'if' b=disjunction 'else' c=expression and generate the message "Syntax Error: statement given where 'body' expression required":

pass if True else 1
break if True else 1
continue if True else 1

The followingexpressions will be handled by a=invalid_ifexp_body_stmt 'if' b=disjunction 'else' c=invalid_ifexp_orelse_stmt and generate the message "Syntax Error: statement given where 'body' expression required":

pass if True else pass
break if True else continue

@sergey-miryanov sergey-miryanov marked this pull request as draft February 9, 2025 06:55
@sergey-miryanov
Copy link
Contributor Author

test_fstring fails, will dig

@sergey-miryanov sergey-miryanov marked this pull request as ready for review February 9, 2025 09:25
@sergey-miryanov sergey-miryanov marked this pull request as draft February 10, 2025 18:35
@sergey-miryanov sergey-miryanov marked this pull request as ready for review February 10, 2025 18:38
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some new comments

@bedevere-app
Copy link

bedevere-app bot commented Feb 12, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@sergey-miryanov
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Feb 13, 2025

Thanks for making the requested changes!

@pablogsal: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from pablogsal February 13, 2025 19:43
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this looks MUCH better. Really well done @sergey-miryanov! 👍

sergey-miryanov and others added 3 commits February 17, 2025 18:25
…e-129515.3L3vmo.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@sergey-miryanov
Copy link
Contributor Author

Thank you all for your review! I made the suggested changes, and it is ready now.

@pablogsal pablogsal merged commit bcc9a5d into python:main Feb 18, 2025
42 checks passed
@pablogsal
Copy link
Member

Excellent job @sergey-miryanov!

Thanks for your contribution 👌

@sergey-miryanov
Copy link
Contributor Author

Thanks!

@sergey-miryanov sergey-miryanov deleted the gh-129515-ifexp-syntax-error branch February 19, 2025 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy