Skip to content
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

gh-121804: always show error location for SyntaxError's in basic repl #123202

Merged
merged 15 commits into from
Sep 3, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Aug 21, 2024

@skirpichev

This comment was marked as resolved.

@skirpichev skirpichev marked this pull request as ready for review August 22, 2024 07:44
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
@pablogsal
Copy link
Member

Sorry @skirpichev but I think this is probably too much complexity (even if the code it's not too difficult to follow) for the fallback that it's not going to be triggered most of the time. Let me check with more core devs to get their input first

@ambv @lysnikolaou what do toy think?

Python/pythonrun.c Outdated Show resolved Hide resolved
@pablogsal
Copy link
Member

If nobody answers by Wednesday next week, ping me and we can merge it. After looking at it I think it may be fine 👍

Ensure to run a bunch of ref leaks manual checks by hand, please. Unfortunately running them in the REPL it's not trivial, but yo can manually compare the output of sys.gettotalrefcount before and after raising.

@skirpichev
Copy link
Member Author

but yo can manually compare the output of sys.gettotalrefcount before and after raising.

@pablogsal, I think that there is no reference leaks, but I can't justify this by sys.gettotalrefcount() output:

$ PYTHON_BASIC_REPL=1 ./python -q
>>> import gc, sys
>>> sys.gettotalrefcount()
61809
>>> gc.collect()
106
>>> sys.gettotalrefcount()
60837
>>> def f(x, x): ...
... 
  File "<stdin>-4", line 1
    def f(x, x): ...
             ^
SyntaxError: duplicate argument 'x' in function definition
>>> gc.collect()
0
>>> sys.gettotalrefcount()
60871
>>> gc.collect()
0
>>> sys.gettotalrefcount()
60883

Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
Python/pythonrun.c Show resolved Hide resolved
Python/pythonrun.c Outdated Show resolved Hide resolved
@lysnikolaou
Copy link
Contributor

@lysnikolaou what do toy think?

Sorry for not replying earlier. I was out on vacation.

I don't have a strong opinion either way, but I agree with the sentiment that might be a bit too complex. It improves a subset of SyntaxErrors for a subset of users that will continue to use the old REPL after they've switched to 3.13 (I don't think this could be backported to earlier versions) with a fairly complicated approach.

Copy link
Contributor

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Personally, I think it's better for the user's experience to show syntax errors correctly, but I don't know whether the basic REPL will be used a lot or not and whether those kind of errors are shown a lot or not. So I'm +0.5.

Python/pythonrun.c Outdated Show resolved Hide resolved
@pablogsal pablogsal enabled auto-merge (squash) September 3, 2024 12:37
@pablogsal pablogsal added the needs backport to 3.13 bugs and security fixes label Sep 3, 2024
@pablogsal pablogsal merged commit 6822cb2 into python:main Sep 3, 2024
40 checks passed
@miss-islington-app
Copy link

Thanks @skirpichev for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 3, 2024
…c repl (pythonGH-123202)

(cherry picked from commit 6822cb2)

Co-authored-by: Sergey B Kirpichev <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 3, 2024

GH-123631 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 3, 2024
@pablogsal
Copy link
Member

Thanks for the pr @skirpichev and thanks @picnixz for your comments 🚀

pablogsal pushed a commit that referenced this pull request Sep 3, 2024
…ic repl (GH-123202) (#123631)

gh-121804: always show error location for SyntaxError's in basic repl (GH-123202)
(cherry picked from commit 6822cb2)

Co-authored-by: Sergey B Kirpichev <[email protected]>
@skirpichev skirpichev deleted the syntaxerr-location-basicrepl-121804 branch September 3, 2024 13:26
@hugovk
Copy link
Member

hugovk commented Sep 4, 2024

@skirpichev For next time, please could you upgrade to blurb 1.2+ so we don't get spaces in the news file path?

https://discuss.python.org/t/new-blurb-1-2-please-upgrade/59159

No need to change this news file. Thanks!

@skirpichev
Copy link
Member Author

skirpichev commented Sep 4, 2024 via email

@hugovk
Copy link
Member

hugovk commented Sep 4, 2024

I plan on enforcing it via CI at some point, maybe after 3.13.0 or 3.14.0a1?

Something like hugovk@e4cc2f7 -> https://github.com/hugovk/cpython/actions/runs/10576194271/job/29301498185

We can't enforce a minimal blurb version as such, people can also use Blurb It (already updated to use underscores) or write them by hand.

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