Skip to content

Commit b0d797f

Browse files
author
Release Manager
committed
gh-40781: simplification in character_art There was a switch "string_type" that could be "str" or "unicode" as an old trace of python2. Nowadays str is unicode and this switch is not needed. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40781 Reported by: Frédéric Chapoton Reviewer(s):
2 parents 71c391a + 203aa13 commit b0d797f

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

src/sage/typeset/ascii_art.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ class AsciiArt(CharacterArt):
181181
pi*x
182182
e
183183
"""
184-
_string_type = str
185184

186185

187186
_ascii_art_factory = CharacterArtFactory(

src/sage/typeset/character_art.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def empty(cls):
103103
sage: from sage.typeset.ascii_art import AsciiArt
104104
sage: AsciiArt.empty()
105105
"""
106-
empty_string = cls._string_type()
107-
return cls([empty_string])
106+
return cls([''])
108107

109108
def __getitem__(self, key):
110109
r"""
@@ -167,7 +166,7 @@ def __format__(self, fmt):
167166
sage: format(unicode_art(M)) # needs sage.modules
168167
'\u239b1 2\u239e\n\u239d3 4\u23a0'
169168
"""
170-
return format(self._string_type(self), fmt)
169+
return format(str(self), fmt)
171170

172171
def get_baseline(self):
173172
r"""

src/sage/typeset/character_art_factory.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def __init__(self,
3737
- ``art_type`` -- type of the character art (i.e. a subclass of
3838
:class:`~sage.typeset.character_art.CharacterArt`)
3939
40-
- ``string_type`` -- type of strings (the lines in the
41-
character art, e.g. ``str`` or ``unicode``)
40+
- ``string_type`` -- ignored (always ``str``)
4241
4342
- ``magic_method_name`` -- name of the Sage magic method (e.g.
4443
``'_ascii_art_'`` or ``'_unicode_art_'``)
@@ -60,8 +59,6 @@ def __init__(self,
6059
<class 'sage.typeset.character_art_factory.CharacterArtFactory'>
6160
"""
6261
self.art_type = art_type
63-
assert isinstance(string_type('a'), str)
64-
self.string_type = string_type
6562
assert magic_method_name in ['_ascii_art_', '_unicode_art_']
6663
self.magic_method_name = magic_method_name
6764
self.left_parenthesis, self.right_parenthesis = parenthesis
@@ -204,13 +201,11 @@ def build_from_string(self, obj, baseline=0):
204201
bb
205202
ccc
206203
"""
207-
if self.string_type is str and not isinstance(obj, str):
204+
if not isinstance(obj, str):
208205
if isinstance(obj, bytes):
209206
obj = obj.decode('utf-8')
210207
else:
211208
obj = str(obj)
212-
if self.string_type is bytes and not isinstance(obj, bytes):
213-
obj = str(obj).encode('utf-8')
214209
return self.art_type(obj.splitlines(), baseline=baseline)
215210

216211
def build_container(self, content, left_border, right_border, baseline=0):
@@ -263,7 +258,7 @@ def build_container(self, content, left_border, right_border, baseline=0):
263258
left_border = left_border.character_art(h)
264259
right_border = right_border.character_art(h)
265260
lines = []
266-
pad = self.string_type(' ')
261+
pad = ' '
267262
for left, line, right in zip(left_border, matrix, right_border):
268263
lines.append(left + pad + line.ljust(w) + pad + right)
269264
shift = len(left_border) + len(pad)
@@ -295,7 +290,7 @@ def build_set(self, s, baseline=0):
295290
{ /\ /\ /\/\ / \ }
296291
{ /\/\/\, /\/ \, / \/\, / \, / \ }
297292
"""
298-
comma = self.art_type([self.string_type(', ')], baseline=0)
293+
comma = self.art_type([', '], baseline=0)
299294
repr_elems = self.concatenate(s, comma, nested=True)
300295
return self.build_container(
301296
repr_elems, self.left_curly_brace, self.right_curly_brace,
@@ -323,10 +318,10 @@ def build_dict(self, d, baseline=0):
323318
sage: ascii_art({'a': '', '': ''})
324319
{ a:, : }
325320
"""
326-
comma = self.art_type([self.string_type(', ')],
321+
comma = self.art_type([', '],
327322
baseline=0,
328323
breakpoints=[1])
329-
colon = self.art_type([self.string_type(':')], baseline=0)
324+
colon = self.art_type([':'], baseline=0)
330325

331326
def concat_no_breakpoint(k, v):
332327
k = self.build(k)
@@ -378,7 +373,7 @@ def build_list(self, l, baseline=0):
378373
22, 23, 24, 25 ], [ 1, 2, 3, 4, 5 ],\n\n
379374
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] ]'
380375
"""
381-
comma = self.art_type([self.string_type(', ')],
376+
comma = self.art_type([', '],
382377
baseline=0,
383378
breakpoints=[1])
384379
repr_elems = self.concatenate(l, comma, nested=True)
@@ -397,7 +392,7 @@ def build_tuple(self, t, baseline=0):
397392
( /\ /\ /\/\ / \ )
398393
( /\/\/\, /\/ \, / \/\, / \, / \ )
399394
"""
400-
comma = self.art_type([self.string_type(', ')],
395+
comma = self.art_type([', '],
401396
baseline=0,
402397
breakpoints=[1])
403398
repr_elems = self.concatenate(t, comma, nested=True)

src/sage/typeset/unicode_art.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class UnicodeArt(CharacterArt):
4949
π⋅x
5050
5151
"""
52-
_string_type = str
5352

5453

5554
_unicode_art_factory = CharacterArtFactory(

0 commit comments

Comments
 (0)