1.1 --- a/micropython/data.py Thu Apr 25 18:08:32 2013 +0200
1.2 +++ b/micropython/data.py Sun Apr 28 19:23:05 2013 +0200
1.3 @@ -7,7 +7,7 @@
1.4 program but which are wrapped in context-dependent structures in the running
1.5 program.
1.6
1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -343,16 +343,19 @@
1.13
1.14 "An attribute entry having a context."
1.15
1.16 - def __init__(self, position, parent, name):
1.17 + def __init__(self, position, parent, name, parent_type=None):
1.18
1.19 """
1.20 Initialise the attribute with the given 'position' within the collection
1.21 - of attributes of its 'parent', indicating its 'name'.
1.22 + of attributes of its 'parent', indicating its 'name'. If the
1.23 + 'parent_type' is specified, it will contain the type of any instance
1.24 + parent.
1.25 """
1.26
1.27 self.position = position
1.28 self.parent = parent
1.29 self.name = name
1.30 + self.parent_type = parent_type
1.31
1.32 # Possible values.
1.33
1.34 @@ -529,9 +532,13 @@
1.35 position = "at %r, " % self.position
1.36 else:
1.37 position = ""
1.38 - return "<attribute %s.%s (%sassigned %r)>" % (
1.39 + if self.parent_type is not None:
1.40 + parent_type = "parent %s, " % shortrepr(self.parent_type)
1.41 + else:
1.42 + parent_type = ""
1.43 + return "<attribute %s.%s (%s%sassigned %r)>" % (
1.44 shortrepr(self.parent), self.name,
1.45 - position, self.assignments
1.46 + parent_type, position, self.assignments
1.47 )
1.48
1.49 def __shortrepr__(self):
1.50 @@ -879,7 +886,7 @@
1.51
1.52 d = {}
1.53 for i, name in enumerate(self._get_position_list(instattr)):
1.54 - d[name] = Attr(i, make_instance(), name)
1.55 + d[name] = Attr(i, make_instance(), name, self)
1.56 return d
1.57
1.58 def _get_position_list(self, positions):