From e77780bc33251052cd704a1b8d6883704c98df60 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sat, 16 Nov 2024 19:01:36 -0700 Subject: [PATCH] Removed AnsiStr.simplify() since that is automatically done --- src/ansi_string/ansi_string.py | 10 ++-------- tests/test_ansi_str.py | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ansi_string/ansi_string.py b/src/ansi_string/ansi_string.py index b578f66..96a32b6 100644 --- a/src/ansi_string/ansi_string.py +++ b/src/ansi_string/ansi_string.py @@ -1676,10 +1676,7 @@ def __new__( *settings:Union[AnsiFormat, AnsiSetting, str, int, list, tuple] ): if isinstance(s, AnsiString): - if settings: - ansi_string = AnsiString(s, *settings) - else: - ansi_string = s + ansi_string = s elif isinstance(s, AnsiStr): if settings: ansi_string = AnsiString(s, *settings) @@ -1691,6 +1688,7 @@ def __new__( ansi_string = AnsiString(s, *settings) else: raise TypeError('Invalid type for s') + ansi_string.simplify() instance = super().__new__(cls, str(ansi_string)) instance.data = ansi_string.base_str return instance @@ -1749,10 +1747,6 @@ def __getitem__(self, val:Union[int, slice]) -> 'AnsiStr': ''' return AnsiStr(AnsiString(str(self)).__getitem__(val)) - def simplify(self): - '''Attempts to simplify formatting by re-parsing the ANSI formatting data''' - return AnsiStr(str(self)) - def apply_formatting( self, settings:Union[AnsiFormat, AnsiSetting, str, int, list, tuple], diff --git a/tests/test_ansi_str.py b/tests/test_ansi_str.py index e83ba48..c106663 100755 --- a/tests/test_ansi_str.py +++ b/tests/test_ansi_str.py @@ -747,7 +747,7 @@ def test_join_first_arg_invalid_type(self): def test_simplify(self): s = AnsiStr('abc', 'green') s = s.apply_formatting('red') - s = s.simplify() + # String should automatically be simplified self.assertEqual(str(s), '\x1b[31mabc\x1b[m') if __name__ == '__main__':