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

Function _common_shorten_repr

Lib/unittest/util.py:33–52  ·  view source on GitHub ↗
(*args)

Source from the content-addressed store, hash-verified

31 return s1
32
33def _common_shorten_repr(*args):
34 args = tuple(map(safe_repr, args))
35 maxlen = max(map(len, args))
36 if maxlen <= _MAX_LENGTH:
37 return args
38
39 prefix = _common_prefix(args)
40 prefixlen = len(prefix)
41
42 common_len = _MAX_LENGTH - \
43 (maxlen - prefixlen + _MIN_BEGIN_LEN + _PLACEHOLDER_LEN)
44 if common_len > _MIN_COMMON_LEN:
45 assert _MIN_BEGIN_LEN + _PLACEHOLDER_LEN + _MIN_COMMON_LEN + \
46 (maxlen - prefixlen) < _MAX_LENGTH
47 prefix = _shorten(prefix, _MIN_BEGIN_LEN, common_len)
48 return tuple(prefix + s[prefixlen:] for s in args)
49
50 prefix = _shorten(prefix, _MIN_BEGIN_LEN, _MIN_COMMON_LEN)
51 return tuple(prefix + _shorten(s[prefixlen:], _MIN_DIFF_LEN, _MIN_END_LEN)
52 for s in args)
53
54def safe_repr(obj, short=False):
55 try:

Callers 6

assert_ns_equalMethod · 0.90
assert_ns_equalMethod · 0.90
_baseAssertEqualMethod · 0.85
assertSequenceEqualMethod · 0.85
assertDictEqualMethod · 0.85
assertMultiLineEqualMethod · 0.85

Calls 2

_common_prefixFunction · 0.85
_shortenFunction · 0.85

Tested by 1

assert_ns_equalMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…