# HG changeset patch # User Paul Boddie # Date 1367169785 -7200 # Node ID 8431cd5ebc653fd0b11ca3251f36de0a346f50f8 # Parent 4d49311d36595c87f019d99e4fb7816ee885ae74 Added a parent type attribute to instance attribute objects. diff -r 4d49311d3659 -r 8431cd5ebc65 micropython/data.py --- a/micropython/data.py Thu Apr 25 18:08:32 2013 +0200 +++ b/micropython/data.py Sun Apr 28 19:23:05 2013 +0200 @@ -7,7 +7,7 @@ program but which are wrapped in context-dependent structures in the running program. -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -343,16 +343,19 @@ "An attribute entry having a context." - def __init__(self, position, parent, name): + def __init__(self, position, parent, name, parent_type=None): """ Initialise the attribute with the given 'position' within the collection - of attributes of its 'parent', indicating its 'name'. + 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 # Possible values. @@ -529,9 +532,13 @@ position = "at %r, " % self.position else: position = "" - return "" % ( + if self.parent_type is not None: + parent_type = "parent %s, " % shortrepr(self.parent_type) + else: + parent_type = "" + return "" % ( shortrepr(self.parent), self.name, - position, self.assignments + parent_type, position, self.assignments ) def __shortrepr__(self): @@ -879,7 +886,7 @@ d = {} for i, name in enumerate(self._get_position_list(instattr)): - d[name] = Attr(i, make_instance(), name) + d[name] = Attr(i, make_instance(), name, self) return d def _get_position_list(self, positions):