Opened 6 years ago

Closed 6 years ago

#21738 closed defect (fixed)

%attach has a weird behaviour when dealing with SyntaxError

Reported by: etn40ff Owned by:
Priority: major Milestone: sage-7.5
Component: interfaces Keywords: %attach
Cc: vbraun, tscrim, chapoton Merged in:
Authors: Volker Braun Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 576d387 (Commits, GitHub, GitLab) Commit: 576d387c948311be4ad0244a198534f6cbbbcd6c
Dependencies: Stopgaps:

Status badges


The new %attach behaves in a strange way when dealing with files that contain errors. Sometimes it parses color escapes sometimes it does not.

Here is how to reproduce the issue:

$ echo "1 + " > /tmp/
$ sage
sage: %attach /tmp/
  File "/tmp/", line 1
    1 +
SyntaxError: invalid syntax

sage: os.system('echo "1 + 1" > /tmp/')
### reloading attached file modified at 12:32:53 ###
sage: os.system('echo "1 + " > /tmp/')
### reloading attached file modified at 12:33:14 ###
?[1;36m  File ?[1;32m"/tmp/"?[1;36m, line ?[1;32m1?[0m
?[1;33m    1 +?[0m
?[1;37m        ^?[0m
?[1;31mSyntaxError?[0m?[1;31m:?[0m invalid syntax


Change History (5)

comment:1 Changed 6 years ago by vbraun

Note that it works the first time (when you call attach yourself) but not when the attached file is changed. In the latter case, there is already a sage: prompt that needs to be erased, the output printed, and the prompt redrawn.

Thats done in IPython's prompt_toolkit patch_stdout_context context, which also screws up ansi sequences.

comment:2 Changed 6 years ago by vbraun

  • Branch set to u/vbraun/_attach_has_a_weird_behaviour_when_dealing_with_syntaxerror

comment:3 Changed 6 years ago by vbraun

  • Authors set to Volker Braun
  • Commit set to 576d387c948311be4ad0244a198534f6cbbbcd6c
  • Status changed from new to needs_review

New commits:

576d387Do not escape ansi sequences in patch_stdout_context

comment:4 Changed 6 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

comment:5 Changed 6 years ago by vbraun

  • Branch changed from u/vbraun/_attach_has_a_weird_behaviour_when_dealing_with_syntaxerror to 576d387c948311be4ad0244a198534f6cbbbcd6c
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.