Invalid hex `colour='#00ff0g'` raises `ValueError` instead of the unknown-colour warning
Author: Q7xM4Created Sep 10, 2026Updated Sep 10, 2026
- I have marked all applicable categories:
- exception-raising bug
- visual output bug
- I have visited the source website, and in particular read the known issues
- I have searched through the issue tracker for duplicates
- I have mentioned version numbers, operating system and
environment, where applicable:
import tqdm, sys print(tqdm.__version__, sys.version, sys.platform)
Bar.colour treats unknown names as a warning (KeyError / AttributeError → TqdmWarning, bar continues uncoloured). A 7-character #...... string that is not valid hex goes through int(..., 16) and raises ValueError, which is not caught.
Reproduction
from io import StringIO
from tqdm import tqdm
list(tqdm(range(1), file=StringIO(), colour="not-a-colour", mininterval=0)) # warns, ok
list(tqdm(range(1), file=StringIO(), colour="#00ff0g", mininterval=0))Output:
/home/tqdm/tqdm/std.py:159: TqdmWarning: Unknown colour (not-a-colour); valid choices: [hex (#00ff00), BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE]
self.colour = colour
Traceback (most recent call last):
File "/home/test.py", line 5, in <module>
list(tqdm(range(1), file=StringIO(), colour="#00ff0g", mininterval=0))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tqdm/tqdm/std.py", line 1103, in __init__
self.refresh(lock_args=self.lock_args)
File "/home/tqdm/tqdm/std.py", line 1354, in refresh
self.display()
File "/home/tqdm/tqdm/std.py", line 1502, in display
self.sp(self.__str__() if msg is None else msg)
^^^^^^^^^^^^^^
File "/home/tqdm/tqdm/std.py", line 1157, in __str__
return self.format_meter(**self.format_dict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tqdm/tqdm/std.py", line 636, in format_meter
full_bar = Bar(frac,
^^^^^^^^^
File "/home/tqdm/tqdm/std.py", line 159, in __init__
self.colour = colour
^^^^^^^^^^^
File "/home/tqdm/tqdm/std.py", line 174, in colour
self._colour = self.COLOUR_RGB % tuple(
^^^^^^
File "/home/tqdm/tqdm/std.py", line 175, in <genexpr>
int(i, 16) for i in (value[1:3], value[3:5], value[5:7]))
^^^^^^^^^^
ValueError: invalid literal for int() with base 16: '0g'Envirenment
>>> print(tqdm.__version__, sys.version, sys.platform)
4.70.1.dev7+g8d6ff8de5 3.12.3 (main, Jun 19 2026, 12:46:00) [GCC 13.3.0] linuxSource: tqdm/tqdm