# HG changeset patch # User Paul Boddie # Date 1335829619 -7200 # Node ID f7c5c829701e3b7e082e89730d0476038f5a20a3 # Parent 9749bccaeca97ce4e1842a3bf3bf4e594b5f9b06 Introduced more concise string representations of data objects. diff -r 9749bccaeca9 -r f7c5c829701e micropython/data.py --- a/micropython/data.py Tue Apr 24 23:51:15 2012 +0200 +++ b/micropython/data.py Tue May 01 01:46:59 2012 +0200 @@ -1109,15 +1109,17 @@ return 0 def __repr__(self): - return "Attr(%r, %s, %r) # {[%s] (%r)}" % ( - self.position, shortrepr(self.parent), self.name, - self._context_values_str(), self.assignments + if self.position is not None: + position = "at %r, " % self.position + else: + position = "" + return "<%s.%s (%sassigned %r)>" % ( + shortrepr(self.parent), self.name, + position, self.assignments ) def __shortrepr__(self): - return "Attr(%r, %s, %r)" % ( - self.position, shortrepr(self.parent), self.name - ) + return "%s.%s (at %r)" % (shortrepr(self.parent), self.name, self.position) def _context_values_str(self): l = [] @@ -1140,7 +1142,7 @@ self.location = None def __repr__(self): - return "Instance()" + return "" def __eq__(self, other): return other.__class__ is Instance @@ -1276,12 +1278,12 @@ def __repr__(self): if self.location is not None: - return "Class(%r, %s, location=%r)" % (self.name, shortrepr(self.parent), self.location) + return "" % (shortrepr(self), self.location) else: - return "Class(%r, %s)" % (self.name, shortrepr(self.parent)) + return "" % shortrepr(self) def __shortrepr__(self): - return "Class(%r, %s)" % (self.name, shortrepr(self.parent)) + return "%s.%s" % (shortrepr(self.parent), self.name) def get_body_block(self): return self.get_instantiator().blocks[0] @@ -1722,18 +1724,14 @@ def __repr__(self): if self.location is not None: - return "Function(%r, %s, %r, location=%r, code_location=%r)" % ( - self.name, shortrepr(self.parent), self.argnames, self.location, self.code_location + return "" % ( + shortrepr(self), self.location, self.code_location ) else: - return "Function(%r, %s, %r)" % ( - self.name, shortrepr(self.parent), self.argnames - ) + return "" % shortrepr(self) def __shortrepr__(self): - return "Function(%r, %s)" % ( - self.name, shortrepr(self.parent) - ) + return "%s.%s(%s)" % (shortrepr(self.parent), self.name, ", ".join(self.argnames)) def get_body_block(self): return self.body_block @@ -1955,9 +1953,10 @@ all_class_attribute_names = class_attribute_names = instance_attribute_names = all_attribute_names def __repr__(self): - return "UnresolvedName(%r, %r)" % (self.name, self.parent_name) - - __shortrepr__ = __repr__ + return "" % shortrepr(self) + + def __shortrepr__(self): + return "%s.%s" % (self.parent_name, self.name) def full_name(self): if self.name is not None: @@ -2004,12 +2003,12 @@ def __repr__(self): if self.location is not None: - return "Module(%r, location=%r)" % (self.name, self.location) + return "" % (self.name, self.location) else: - return "Module(%r)" % self.name + return "" % shortrepr(self) def __shortrepr__(self): - return "Module(%r)" % self.name + return self.name # Attribute methods.