MCPcopy Index your code
hub / github.com/python/cpython / _display_width

Function _display_width

Lib/traceback.py:976–993  ·  view source on GitHub ↗

Calculate the extra amount of width space the given source code segment might take if it were to be displayed on a fixed width output device. Supports wide unicode characters and emojis.

(line, offset=None)

Source from the content-addressed store, hash-verified

974_WIDE_CHAR_SPECIFIERS = "WF"
975
976def _display_width(line, offset=None):
977 """Calculate the extra amount of width space the given source
978 code segment might take if it were to be displayed on a fixed
979 width output device. Supports wide unicode characters and emojis."""
980
981 if offset is None:
982 offset = len(line)
983
984 # Fast track for ASCII-only strings
985 if line.isascii():
986 return offset
987
988 import unicodedata
989
990 return sum(
991 2 if unicodedata.east_asian_width(char) in _WIDE_CHAR_SPECIFIERS else 1
992 for char in line[:offset]
993 )
994
995
996def _format_note(note, indent, theme):

Callers 3

format_frame_summaryMethod · 0.85
output_lineMethod · 0.85
_format_syntax_errorMethod · 0.85

Calls 1

isasciiMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…