Handle passing non-string types into crayons

Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
This commit is contained in:
Matthew Peveler
2020-06-05 02:38:57 -04:00
parent 1495890f8c
commit fb04b80e3c
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ class ColoredString(object):
if not PY3 and isinstance(s, unicode): # noqa: F821
self.s = s.encode('utf-8')
else:
self.s = s
self.s = str(s)
self.color = REPLACE_COLORS.get(color, color)
self.always_color = always_color
self.bold = bold
+2
View File
@@ -8,8 +8,10 @@ print(crayons.red('red string'))
print('{} white {}'.format(crayons.red('red'), crayons.blue('blue')))
crayons.disable()
print('{} white {}'.format(crayons.red('red'), crayons.blue('blue')))
print('non-string value {!s}'.format(crayons.red(1234)))
crayons.enable()
print('{} white {}'.format(crayons.red('red'), crayons.blue('blue')))
print('non-string value {!s}'.format(crayons.red(1234)))
print(crayons.red('red string', bold=True))
print(crayons.yellow('yellow string', bold=True))
print(crayons.magenta('magenta string', bold=True))