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

Class Repr

Lib/reprlib.py:38–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36 return decorating_function
37
38class Repr:
39 _lookup = {
40 'tuple': 'builtins',
41 'list': 'builtins',
42 'array': 'array',
43 'set': 'builtins',
44 'frozenset': 'builtins',
45 'deque': 'collections',
46 'dict': 'builtins',
47 'str': 'builtins',
48 'int': 'builtins'
49 }
50
51 def __init__(
52 self, *, maxlevel=6, maxtuple=6, maxlist=6, maxarray=5, maxdict=4,
53 maxset=6, maxfrozenset=6, maxdeque=6, maxstring=30, maxlong=40,
54 maxother=30, fillvalue='...', indent=None,
55 ):
56 self.maxlevel = maxlevel
57 self.maxtuple = maxtuple
58 self.maxlist = maxlist
59 self.maxarray = maxarray
60 self.maxdict = maxdict
61 self.maxset = maxset
62 self.maxfrozenset = maxfrozenset
63 self.maxdeque = maxdeque
64 self.maxstring = maxstring
65 self.maxlong = maxlong
66 self.maxother = maxother
67 self.fillvalue = fillvalue
68 self.indent = indent
69
70 def repr(self, x):
71 return self.repr1(x, self.maxlevel)
72
73 def repr1(self, x, level):
74 cls = type(x)
75 typename = cls.__name__
76
77 if ' ' in typename:
78 parts = typename.split()
79 typename = '_'.join(parts)
80
81 method = getattr(self, 'repr_' + typename, None)
82 if method:
83 # not defined in this class
84 if typename not in self._lookup:
85 return method(x, level)
86 module = getattr(cls, '__module__', None)
87 # defined in this class and is the module intended
88 if module == self._lookup[typename]:
89 return method(x, level)
90
91 return self.repr_instance(x, level)
92
93 def _join(self, pieces, level):
94 if self.indent is None:
95 return ', '.join(pieces)

Callers 6

test_init_kwargsMethod · 0.90
test_tupleMethod · 0.90
test_valid_indentMethod · 0.90
test_invalid_indentMethod · 0.90
debugobj.pyFile · 0.90
reprlib.pyFile · 0.85

Calls

no outgoing calls

Tested by 4

test_init_kwargsMethod · 0.72
test_tupleMethod · 0.72
test_valid_indentMethod · 0.72
test_invalid_indentMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…