Remove distracted red bar from IDLE for some SyntaxErrors

Abierto
#93,966 3 comentarios 0 reacciones 1 asignado Ver en GitHub

@terryjreedy ya está trabajando en esto.

Desde el 17/6/2022.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

topic-IDLE type-bug

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
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.