You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
❯ 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:
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.
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.
Activity
samuelcolvin commentedon Oct 21, 2020
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.
radcool commentedon Oct 21, 2020
@samuelcolvin it looks like the issue occurs in Python 3.8.6, but not in 3.8.5:
radcool commentedon Oct 21, 2020
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.
samuelcolvin commentedon Oct 21, 2020
radcool commentedon Oct 21, 2020
After bisecting with Git this is what I get:
The change in
Lib/enum.pyis this: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

enumI found in the devtools code base is this: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.
samuelcolvin commentedon Oct 21, 2020
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=falsewhich disables highlighting and means
debug()is at least usable.samuelcolvin commentedon Oct 21, 2020
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.compatibility with python 3.8.6, fix #73
compatibility with python 3.8.6 (#74)
samuelcolvin commentedon Oct 22, 2020
fixed and deployed in v0.6.1, thanks so much for your pointers, it made it much faster to fix.
radcool commentedon Oct 22, 2020
My pleasure!