Remove distracted red bar from IDLE for some SyntaxErrors
@terryjreedy ci sta già lavorando.
Dal 17/6/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Bug report
This may be more an distracting cosmetic issue than a true bug, but it is something that can be fixed easily.
As Raymond Hettinger mentioned a while ago on Twitter (https://twitter.com/raymondh/status/1501700903870468099), when a SyntaxError is raised and the location corresponds to the "\n" at the end of a line, a huge red highlighted region is shown at the end of the invalid line.
For example, type
from math
followed by enter. This red highlighted line will remain on the screen until another SyntaxError occurs.
Unlike cases where a SyntaxError highlights just a few characters pointing at a specific problem, this adds really no informative value, once the user starts entering some new code.
Your environment
I have reproduced this will IDLE on Windows 10 on all Python versions I have installed, from 3.6 to 3.11 inclusively.
Proposed fix
I have been able to fix this on a custom version of IDLE (friendly_idle) by doing the following:
In pyshell.ModifiedInterpreter.transfer_path which sets up some values at the beginning of a new process,
define the following:
self.error_at_end_of_line = False
In pyshell.ModifiedInterpreter.showsyntaxerror, add the last line shown below:
if lineno == 1:
pos = "iomark + %d chars" % (offset - 1)
else:
pos = "iomark linestart + %d lines + %d chars" % (lineno - 1, offset - 1)
self.error_at_end_of_line = text.get(pos) == "\n" # <-- add this
At the beginning of pyshell.ModifiedInterpreter.runsource, add the following:
if self.error_at_end_of_line:
self.error_at_end_of_line = False
self.tkconsole.text.tag_remove("ERROR", "1.0", "end")
If desired, I could do a pull request that would include these changes.
Linked PRs
- gh-157595
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·