class BinaryData(object): '''The minimal example''' def __init__(self, data): if not data: raise TypeError("no data to parse") if len(data) <= 1: raise ValueError("data too short") self.data = data self.length = len(data) def __repr__(self): # The debugger runs this before __init__ is even done, so it will # complain about BinaryData not having an attribute length return "<%s: length %d>" % (self.__class__.__name__, self.length) # If you replace the above with this (or remove __repr__ entirely), # it works fine # return "A constant string"