← 输入框|github.com|刷新
Skip to content

debug() output suddenly styled weirdly #73

Closed
sthagen/samuelcolvin-python-devtools
#4

Description

@radcool

Hi,

I've been using the debug() function of devtools to print out some data structures for about 1-2 months now and I've been loving it!

After taking a break from a Python program for about 2 weeks I've gone back to start improving it again and I've noticed that now, when I use debug(), the colorized output looks very weird. Since I haven't seen any other GitHub issues on the subject I'm sure the problem is on my end, but I can't figure out what it is.

To simplify things, I've created a new venv, installed devtools and Pygments using the suggested pip install devtools[pygments]:

❯ pip list
Package    Version
---------- -------
devtools   0.6
pip        20.2.4
Pygments   2.7.1
setuptools 49.2.1

❯ python -V
Python 3.8.6

and created the simplest program I could think of:

#!/usr/bin/env python

from devtools import debug

a = 5

debug(a)

Still, the output is like this:

image

I normally use Bash on ArchLinux, but I've tried running this in Fish with the same result. I have installed a fresh Fedora 32 Workstation in a VM, created a new venv, and tried the same program, and get the same result.

I really don't understand why I am suddenly getting this results and what I am doing wrong.

Any tips/hints on where I should look to troubleshoot further? Thanks.

Activity

  1. samuelcolvin commented on Oct 21, 2020

    @samuelcolvin
    Owner

    I've just started having the same problem too!

    I've been meaning to look into it, I'm on macos.

    I'll try and look into it asap.

    Any other hints on what it might be would be useful. It looks like the ansi encoding had broken.

  2. radcool commented on Oct 21, 2020

    @radcool
    Author

    @samuelcolvin it looks like the issue occurs in Python 3.8.6, but not in 3.8.5:

    image

  3. radcool commented on Oct 21, 2020

    @radcool
    Author

    I am bisecting the CPython code between 3.8.5 and 3.8.6 to see if I can find the exact commit where the issue starts.

  4. samuelcolvin commented on Oct 21, 2020

    @samuelcolvin
    Owner
  5. radcool commented on Oct 21, 2020

    @radcool
    Author

    After bisecting with Git this is what I get:

    ❯ git bisect good
    38c8d3930eb872258a82339bcba3bce1d0e3ac2c is the first bad commit
    commit 38c8d3930eb872258a82339bcba3bce1d0e3ac2c
    Author: Ethan Furman <ethan@stoneleaf.us>
    Date:   Sun Sep 13 13:47:43 2020 -0700
    
        [3.8] bpo-37479: Enum - use correct __format__ (GH-14545)
        
        * bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__.
        (cherry picked from commit 2f19e82fbe98ce86bcd98a176328af2808b678e8)
        
        Co-authored-by: thatneat <thatneat@users.noreply.github.com>
    
     Doc/library/enum.rst                               |  8 ++--
     Lib/enum.py                                        |  5 +-
     Lib/test/test_enum.py                              | 53 +++++++++++++++++++++-
     Misc/ACKS                                          |  1 +
     .../2019-07-02-12-43-57.bpo-37479.O53a5S.rst       |  2 +
     5 files changed, 63 insertions(+), 6 deletions(-)
     create mode 100644 Misc/NEWS.d/next/Library/2019-07-02-12-43-57.bpo-37479.O53a5S.rst
    

    The change in Lib/enum.py is this:

    diff --git a/Lib/enum.py b/Lib/enum.py
    index 14cc00e783..16033b1c6f 100644
    --- a/Lib/enum.py
    +++ b/Lib/enum.py
    @@ -633,8 +633,9 @@ class Enum(metaclass=EnumMeta):
             # we can get strange results with the Enum name showing up instead of
             # the value
     
    -        # pure Enum branch
    -        if self._member_type_ is object:
    +        # pure Enum branch, or branch with __str__ explicitly overridden
    +        str_overridden = type(self).__str__ != Enum.__str__
    +        if self._member_type_ is object or str_overridden:
                 cls = str
                 val = str(self)
             # mix-in branch
    

    I can confirm that applying this change manually also results in getting the wonky output with debug(), so this change in CPython really seems to be the "culprit".

    The only mention of enum I found in the devtools code base is this:
    image

    This is WAY beyond my knowledge of Python, so while I can assume that the two are related, I have no idea how they are related.

  6. samuelcolvin commented on Oct 21, 2020

    @samuelcolvin
    Owner

    Should be fixable, thank you so much for looking into this.

    In the meantime, the workaround I'm currently using is setting

    export PY_DEVTOOLS_HIGHLIGHT=false

    which disables highlighting and means debug() is at least usable.

  7. samuelcolvin commented on Oct 21, 2020

    @samuelcolvin
    Owner

    Kind of make sense if you read https://bugs.python.org/issue37479, we override __str__ to give a nice description of the colors, but with the change above it means that nice description, instead of the raw number is being inserted into the ansi escape sequences.

  8. added a commit that references this issue on Oct 22, 2020
    61f8379
  9. added a commit that references this issue on Oct 22, 2020
    4bef4c3
  10. samuelcolvin commented on Oct 22, 2020

    @samuelcolvin
    Owner

    fixed and deployed in v0.6.1, thanks so much for your pointers, it made it much faster to fix.

  11. radcool commented on Oct 22, 2020

    @radcool
    Author

    My pleasure!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions