MCPcopy Index your code
hub / github.com/plotly/plotly.py / __repr__

Method __repr__

plotly/utils.py:74–109  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

72 return False
73
74 def __repr__(self):
75 numpy = get_module("numpy")
76 if isinstance(self.v, (list, tuple)):
77 # Handle lists/tuples
78 res = _list_repr_elided(
79 self.v, threshold=self.threshold, indent=self.indent
80 )
81 return res
82 elif numpy and isinstance(self.v, numpy.ndarray):
83 # Handle numpy arrays
84
85 # Get original print opts
86 orig_opts = numpy.get_printoptions()
87
88 # Set threshold to self.max_list_elements
89 numpy.set_printoptions(
90 **dict(orig_opts, threshold=self.threshold, edgeitems=3, linewidth=80)
91 )
92
93 res = self.v.__repr__()
94
95 # Add indent to all but the first line
96 res_lines = res.split("\n")
97 res = ("\n" + " " * self.indent).join(res_lines)
98
99 # Restore print opts
100 numpy.set_printoptions(**orig_opts)
101 return res
102 elif isinstance(self.v, str):
103 # Handle strings
104 if len(self.v) > 80:
105 return "(" + repr(self.v[:30]) + " ... " + repr(self.v[-30:]) + ")"
106 else:
107 return self.v.__repr__()
108 else:
109 return self.v.__repr__()
110
111
112class ElidedPrettyPrinter(PrettyPrinter):

Callers

nothing calls this directly

Calls 3

get_moduleFunction · 0.90
_list_repr_elidedFunction · 0.85
splitMethod · 0.45

Tested by

no test coverage detected