Visitar URL original
bpo-24665: double-width CJK chars support for textwrap by fgallaire · Pull Request #89 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix Python build problems
  • Loading branch information
fgallaire committed Feb 15, 2017
commit 54de7aa6c6fffe9b2248153051a24b0e658bf665
2 changes: 1 addition & 1 deletion Lib/idlelib/idle_test/test_calltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_signature_wrap(self):
(width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
placeholder=' [...]')''')
placeholder=' [...]', cjk=False)''')

def test_docline_truncation(self):
def f(): pass
Expand Down
2 changes: 1 addition & 1 deletion Lib/textwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Written by Greg Ward <gward@python.net>

import re
import unicodedata

__all__ = ['TextWrapper', 'wrap', 'fill', 'dedent', 'indent', 'shorten',
'cjk_wide', 'cjk_len', 'cjk_slices']
Expand Down Expand Up @@ -428,6 +427,7 @@ def cjk_wide(char):
"""Return True if char is Fullwidth or Wide, False otherwise.
Fullwidth and Wide CJK chars are double-width.
"""
import unicodedata

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think importing unicodedata, when wanted, for each char, is wrong. If not imported at the top, it could be imported as a global in TextWrapper.init when cjk is true. (I am assuming that the convenience functions all instantiate TextWrapper.

return unicodedata.east_asian_width(char) in ('F', 'W')

This comment was marked as resolved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, @duboviy or @Haypo, could you explain to me why/how a tuple could be slower than a frozenset.



Expand Down