-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-56708: support custom len function in textwrap.wrap #28136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
df3f367
97a2ec8
db82b6c
f457e20
e164780
09ce4ce
bf8dad5
68e8098
e5d6d88
7b32d0b
b811049
95fcafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| # | ||
|
|
||
| import unittest | ||
| import unicodedata | ||
|
|
||
| from textwrap import TextWrapper, wrap, fill, dedent, indent, shorten | ||
|
|
||
|
|
@@ -1076,5 +1077,21 @@ def test_first_word_too_long_but_placeholder_fits(self): | |
| self.check_shorten("Helloo", 5, "[...]") | ||
|
|
||
|
|
||
| class WideCharacterTestCase(BaseTestCase): | ||
| def test_wide_character(self): | ||
| def text_len(text): | ||
| n = 0 | ||
| for c in text: | ||
| if unicodedata.east_asian_width(c) in {'F', 'W'}: | ||
| n += 2 | ||
| else: | ||
| n += 1 | ||
| return n | ||
|
|
||
| text = "123 🔧" | ||
| expected = ["123", "🔧"] | ||
| self.check_wrap(text, 5, expected, text_len=text_len) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that more tests are needed; text_len is used at multiple places in the code.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding tests! Could some of them use different texts?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to avoid adding example for languages that I do not speak myself (e.g. Chinese). Are there ways to reach out to the wider community to provide meaningful examples? |
||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Uh oh!
There was an error while loading. Please reload this page.