Skip to content

Commit

Permalink
compatibility with python 3.8.6 (#74)
Browse files Browse the repository at this point in the history
* compatibility with python 3.8.6, fix #73

* uprev
  • Loading branch information
samuelcolvin authored Oct 22, 2020
1 parent cd9bdee commit 4bef4c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions devtools/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

MYPY = False
if MYPY:
from typing import Any
from typing import Any, Union


def strip_ansi(value):
Expand Down Expand Up @@ -93,15 +93,15 @@ def __call__(self, input: 'Any', *styles: 'Style', reset: bool = True, apply: bo
s = self.styles[s]
except KeyError:
raise ValueError('invalid style "{}"'.format(s))
codes.append(str(s.value))
codes.append(_style_as_int(s.value))

if codes:
r = _ansi_template.format(';'.join(codes)) + text
else:
r = text

if reset:
r += _ansi_template.format(self.reset)
r += _ansi_template.format(_style_as_int(self.reset))
return r

@property
Expand All @@ -121,6 +121,13 @@ def __str__(self):
return super().__str__()


def _style_as_int(v: 'Union[Style, int]') -> str:
if isinstance(v, Style):
return str(v.value)
else:
return str(v)


sformat = Style(-1)


Expand Down
2 changes: 1 addition & 1 deletion devtools/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ('VERSION',)

VERSION = '0.6'
VERSION = '0.6.1'

0 comments on commit 4bef4c3

Please sign in to comment.