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

Misleading error location reported by ellipsis preparser #38949

Open
2 tasks done
user202729 opened this issue Nov 10, 2024 · 1 comment
Open
2 tasks done

Misleading error location reported by ellipsis preparser #38949

user202729 opened this issue Nov 10, 2024 · 1 comment
Labels

Comments

@user202729
Copy link
Contributor

Steps To Reproduce

for a in [0..2]:
	for b in 0..2:
		pass

Expected Behavior

The error is reported on the second line.

Actual Behavior

  Cell In[118], line 1
    for a in [Integer(0)..Integer(2)]:
                         ^
SyntaxError: invalid syntax

Additional Information

No response

Environment

  • OS: Linux
  • Sage Version: 10.4

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@DaveWitteMorris
Copy link
Member

Thanks for the bug report. This error message is not actually coming from the preparser. The ellipsis preparser does raise an exception:

SyntaxError: unbalanced or missing delimiters

However, this exception is ignored (lines 1784 to 1787 of src/sage/repl/preparse.py):

try:
    L = parse_ellipsis(L, preparse_step=False)
except SyntaxError:
    pass

Because it raises an error instead of returning a value, the parse_ellipsis method doesn't end up doing anything, so the original (un-preparsed) code is passed to python. The first .. in the code hasn't been preparsed (it is still[Integer(0)..Integer(2)] instead of (ellipsis_range(Integer(1),Ellipsis,Integer(2))), so this is not valid python. This results in the SyntaxError that we see when the code is executed.

There doesn't seem to be much point in having parse_ellipsis raise an exception that is going to be ignored, so perhaps a way to fix the problem would be to add a boolean keyword argument to parse_ellipsis telling it not to raise a SyntaxError, and instead return a string after doing as much preparsing as possible. In the given example, this should mean that the syntax error comes up in the right place.

However, I don't plan to work on this (not soon, at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants