Ask Your Question
2

Preparser not working if cell starts with a comment

asked 2020-12-27 18:49:45 +0200

Florentin Jaffredo gravatar image

Some of my code stopped working after I upgraded from version 9.0 to 9.3beta4. I tracked it to the following bug:

sage: preparse('1 # Comment \n 1.5^2')
"Integer(1) # Comment \n RealNumber('1.5')**Integer(2)"

sage: preparse('# Comment \n 1.5^2')
'# Comment \n 1.5^2'

The code is not getting preparsed if it starts with a comment. In practice it looks like this:

image description

This seems like a big issue, and I would be surprised if it went unnoticed until now. Could it be caused by my Sage installation? (Compiled from source on WSL2 Ubuntu 20.04, which is not officially supported, but I didn't notice anything weird).
Can someone try this?

edit retag flag offensive close merge delete

Comments

I confirm the issue with Sage 9.3.beta4. With Sage 9.2, the bug appears only the console: everything is fine in the Jupyter notebook.

eric_g gravatar imageeric_g ( 2020-12-27 19:12:07 +0200 )edit

Thanks Eric for the quick reply. The same is true for Sage 9.0. I wonder what changed, and how was it working previously.

Florentin Jaffredo gravatar imageFlorentin Jaffredo ( 2020-12-27 21:13:30 +0200 )edit

Looking at the code for preparse, it starts with

L = line.lstrip()
if len(L) > 0 and L[0] in ['#', '!']:
    return line

That code has been there since at least 2014, and perfectly explains the first observation. An easy fix would probably be to check here for a line break, but that doesn't explain why it was working before.

Florentin Jaffredo gravatar imageFlorentin Jaffredo ( 2020-12-27 22:02:48 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-27 23:48:38 +0200

slelievre gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-12-27 18:49:45 +0200

Seen: 187 times

Last updated: Dec 27 '20