Skip to content

Commit bf8dad5

Browse files
committed
optimize text_len function
1 parent 09ce4ce commit bf8dad5

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

Lib/test/test_textwrap.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,10 @@ def test_first_word_too_long_but_placeholder_fits(self):
10791079

10801080
class WideCharacterTestCase(BaseTestCase):
10811081
def text_len(self, text):
1082-
n = 0
1083-
for c in text:
1084-
if unicodedata.east_asian_width(c) in {'F', 'W'}:
1085-
n += 2
1086-
else:
1087-
n += 1
1088-
return n
1082+
sum(
1083+
2 if unicodedata.east_asian_width(c) in {'F', 'W'} else 1
1084+
for c in text
1085+
)
10891086

10901087
def check_shorten(self, text, width, expect, **kwargs):
10911088
result = shorten(text, width, **kwargs)

0 commit comments

Comments
 (0)