Skip to content

Use color to highlight error locations #112730

Description

@pablogsal

This has several advantages:

  • Will help a lot with readability as parsing the error lines is easier if color highlights the error ranges.
  • In the future we can optionally (via config) drop the ranges and only use color, recovering back the extra lines that the carets are taking.
  • All the cool kids are doing it: This feature has already been successfully implemented in various tools. It has proven to be an effective aid for developers in quickly identifying the source and location of errors.

Control features:

Linked PRs

Activity

  1. added 2 commits that reference this issue on Dec 4, 2023
  2. assigned and unassigned on Dec 4, 2023
  3. added 6 commits that reference this issue on Dec 4, 2023
  4. hugovk commented on Dec 5, 2023

    @hugovk
    Member

    This looks really good, thanks!

    Perhaps something for a followup, can we customise the colouring a bit?

    PR #112732 right now:

    image

    GitHub / MagicPython

    GitHub markdown (with pytb after the triple backticks):

    Traceback (most recent call last):
      File "/Users/hugo/github/python/cpython/main/1.py", line 1, in <module>
        1/0
        ~^~
    ZeroDivisionError: division by zero
    (GitHub screenshot)

    image

    (Uses https://github.com/MagicStack/MagicPython for Python tracebacks: https://github.com/github-linguist/linguist/blob/master/vendor/README.md)

    Sphinx / pygments

    Sphinx with .. code-block:: pytb, for example on the PEPs repo:

    image

    (Uses Pygments' Native style)

  5. pablogsal commented on Dec 5, 2023

    @pablogsal
    MemberAuthor

    Perhaps something for a followup, can we customise the colouring a bit?

    Yup, see #112732 (comment).

    I want to explore customization options AFTER we land the basic version first. EDIT Or are you referring to customizing the coloring as "adding more colors"?

    On the other hand, are you suggesting to also colorize the name of the exception, the file, the number and the Traceback text?

    I have been told that yellow and cian are really bad for light mode, so we should do something else there.

  6. pablogsal commented on Dec 5, 2023

    @pablogsal
    MemberAuthor

    @hugovk What about like this?

    Screenshot 2023-12-05 at 14 11 59
    Screenshot 2023-12-05 at 14 12 54

  7. hugovk commented on Dec 5, 2023

    @hugovk
    Member

    I wasn't thinking about allowing the user to customise them (although that's something to consider) but about having different colours for the different elements (exception name, file, etc).

    Yes, we should check the contrast is good for both light and dark modes.

    The GitHub colours (ignoring the plain black/white text) look the same for each mode and display well for both:

    image

    image

    edit: and the blues are different, but you get the idea :)

  8. pablogsal commented on Dec 5, 2023

    @pablogsal
    MemberAuthor

    I am quite colorblind myself 😅 Do you mind telling me what colors are supposed to be every piece? As in "filename is ..., line number is ...., function name is ..., source code is ..., error location is ...)

  9. 19 remaining items

  10. pablogsal commented on Apr 8, 2024

    @pablogsal
    MemberAuthor

    Maybe we could just add a support decorator that just does the appropriate monkey patching in the colorise function to avoid being affected by the force colours variable. To avoid regressions, setting FORCE_COLORS in GH actions sounds like a good idea.

  11. pablogsal commented on Apr 8, 2024

    @pablogsal
    MemberAuthor

    I personally think it's very useful for Python to use the same env vars that are being increasingly widely adopted elsewhere. So I suppose I lean towards changing -E so that it also ignores the FORCE_COLOR variable.

    I think if we don't do this it's going to be a full pain for us and a lot of users that have the variable set in CI and are running subprocesses in tests

  12. added a commit that references this issue on Apr 9, 2024
  13. added 2 commits that reference this issue on Apr 19, 2024
  14. added a commit that references this issue on Apr 24, 2024
  15. encukou commented on Apr 25, 2024

    @encukou
    Member

    #117672 broke several stable buildbots, see e.g. here. As Jakub noted they seem to be --enable-shared builds that rely on LD_LIBRARY_PATH to find libpython.

    Do you have time to look into this?

  16. pablogsal commented on Apr 25, 2024

    @pablogsal
    MemberAuthor

    I will look into this today. We can revert in the meanwhile if you wish

  17. added 2 commits that reference this issue on Apr 25, 2024
  18. pablogsal commented on Apr 26, 2024

    @pablogsal
    MemberAuthor

    I think this will be fixed by #118288

  19. hugovk commented on Jun 15, 2024

    @hugovk
    Member

    #118288 has been merged, closing.

  20. added 2 commits that reference this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixestype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions