def repr(self, x, level=None): if level is None: level = self.maxlevel for cls in inspect.getmro(correct_type(x)): if cls in supressed_classes: return basic_repr(x)[:-1] + ' (expensive repr suppressed)>' func = repr_registry.get(cls) if func: return func(x, ReprHelper(self, level, func)) return repr(x)
def repr_object(x, helper): try: s = repr(x) # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except Exception: return basic_repr(x) if len(s) > suppression_threshold: cls = correct_type(x) supressed_classes.add(cls) warnings.warn('%s.__repr__ is too long and has been supressed. ' 'Register a cheap repr for the class to avoid this warning ' 'and see an informative repr again.' % safe_qualname(cls)) return helper.truncate(s)
def __getitem__(self, item): t = correct_type(item) with self.lock: return self.data[t]
def type_name(x): return safe_qualname(correct_type(x))