# HG changeset patch # User Paul Boddie # Date 1382889243 -3600 # Node ID f0ec81f0678fae802e239420b62dc2562cefe96a # Parent 7aec95a715a8c85867fe77ae581d6bcbbc2cb618 Moved position information into the Attr class from BaseAttr since LocalAttr is not likely to be used when defining attribute positioning. diff -r 7aec95a715a8 -r f0ec81f0678f micropython/data.py --- a/micropython/data.py Sun Oct 27 02:55:51 2013 +0200 +++ b/micropython/data.py Sun Oct 27 16:54:03 2013 +0100 @@ -392,16 +392,14 @@ "A basic attribute entry." - def __init__(self, position, parent, name, parent_type=None): + def __init__(self, parent, name, parent_type=None): """ - Initialise the attribute with the given 'position' within the collection - of attributes of its 'parent', indicating its 'name'. If the - 'parent_type' is specified, it will contain the type of any instance - parent. + Initialise the attribute within the collection of attributes of its + 'parent', indicating its 'name'. If the 'parent_type' is specified, it + will contain the type of any instance parent. """ - self.position = position self.parent = parent self.name = name self.parent_type = parent_type @@ -541,21 +539,19 @@ return True def __repr__(self): - if self.position is not None: - position = "at %r, " % self.position - else: - position = "" - if self.parent_type is not None: - parent_type = "parent %s, " % shortrepr(self.parent_type) - else: - parent_type = "" - return "" % ( + return "" % ( shortrepr(self.parent), self.name, - parent_type, position, self.get_assignments() + self._repr_parent_type(), self.get_assignments() ) + def _repr_parent_type(self): + if self.parent_type is not None: + return "parent %s, " % shortrepr(self.parent_type) + else: + return "" + def __shortrepr__(self): - return "%s.%s (at %r)" % (shortrepr(self.parent), self.name, self.position) + return "%s.%s" % (shortrepr(self.parent), self.name) class LocalAttr(BaseAttr): @@ -601,7 +597,16 @@ "An attribute entry having context and value information." def __init__(self, position, parent, name, parent_type=None): - BaseAttr.__init__(self, position, parent, name, parent_type) + + """ + Initialise the attribute with the given 'position' within the collection + of attributes of its 'parent', indicating its 'name'. If the + 'parent_type' is specified, it will contain the type of any instance + parent. + """ + + BaseAttr.__init__(self, parent, name, parent_type) + self.position = position # Possible values. @@ -655,6 +660,23 @@ else: self.assignments += AtLeast(n) + def __repr__(self): + return "" % ( + shortrepr(self.parent), self.name, + self._repr_parent_type(), self._repr_position(), + self.get_assignments() + ) + + def _repr_position(self): + if self.position is not None: + return "at %r, " % self.position + else: + return "" + + def __shortrepr__(self): + return "%s.%s (at %r)" % (shortrepr(self.parent), self.name, + self._repr_position()) + class Class(NamespaceDict, Naming, Constant): "A base class for common/normal classes and the type class."