#29165 closed defect (duplicate)

Preparsing of sage file can lead to weird and inconsistent behavior

Reported by: bouvier Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: user interface Keywords: preparse preparser runfile
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

If one execute the following script in Sage interpreter:

2 = 3
print (2)

one will get a exception

ValueError: The name "2" is not a valid Python identifier.

which is expected.

But if one execute it from a file with sage file.sage or in the interpreter with %runfile file.sage, one does not get an error and the script simply prints 3.

This is due to the fact that Sage preparse the file before running it; if one looks into the generated file.sage.py, one can see that the integers are replaced by _sage_const_nnn, even when the integer is on the left-hand-side of an equality. As it is a valid python identifier, there is no error anymore and its value can be modified.

Change History (4)

comment:1 Changed 14 months ago by nbruin

This has definitely been noted before, e.g. sage-devel thread.

comment:2 Changed 14 months ago by nbruin

  • Milestone changed from sage-9.1 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

duplicate of #11542?

comment:3 Changed 14 months ago by vdelecroix

  • Status changed from needs_review to positive_review

agreed

comment:4 Changed 14 months ago by vdelecroix

  • Resolution set to duplicate
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.