diff --git a/Lib/reprlib.py b/Lib/reprlib.py index 767506cd335fa2..4f398bd4dbda28 100644 --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -69,6 +69,12 @@ def _join(self, pieces, level): if not pieces: return '' indent = self.indent + if not isinstance(indent, str): + if not isinstance(indent, int) or indent < 0: + raise ValueError( + "Repr.indent must be None, str or non-negative int, not " + + repr(indent) + ) if isinstance(indent, int): indent *= ' ' sep = ',\n' + (self.maxlevel - level + 1) * indent