MCPcopy Index your code
hub / github.com/ipython/ipython / _elide_point

Function _elide_point

IPython/terminal/ptutils.py:31–66  ·  view source on GitHub ↗

If a string is long enough, and has at least 3 dots, replace the middle part with ellipses. If a string naming a file is long enough, and has at least 3 slashes, replace the middle part with ellipses. If three consecutive dots, or two consecutive dots are encountered these are

(string: str, *, min_elide)

Source from the content-addressed store, hash-verified

29
30
31def _elide_point(string: str, *, min_elide) -> str:
32 """
33 If a string is long enough, and has at least 3 dots,
34 replace the middle part with ellipses.
35
36 If a string naming a file is long enough, and has at least 3 slashes,
37 replace the middle part with ellipses.
38
39 If three consecutive dots, or two consecutive dots are encountered these are
40 replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode
41 equivalents
42 """
43 string = string.replace('...','\N{HORIZONTAL ELLIPSIS}')
44 string = string.replace('..','\N{TWO DOT LEADER}')
45 if len(string) < min_elide:
46 return string
47
48 object_parts = string.split('.')
49 file_parts = string.split(os.sep)
50 if file_parts[-1] == '':
51 file_parts.pop()
52
53 if len(object_parts) > 3:
54 return "{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}".format(
55 object_parts[0],
56 object_parts[1][:1],
57 object_parts[-2][-1:],
58 object_parts[-1],
59 )
60
61 elif len(file_parts) > 3:
62 return ("{}" + os.sep + "{}\N{HORIZONTAL ELLIPSIS}{}" + os.sep + "{}").format(
63 file_parts[0], file_parts[1][:1], file_parts[-2][-1:], file_parts[-1]
64 )
65
66 return string
67
68
69def _elide_typed(string: str, typed: str, *, min_elide: int) -> str:

Callers 1

_elideFunction · 0.85

Calls 3

replaceMethod · 0.80
popMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…