1.1 --- a/micropython/__init__.py Sat Jan 12 18:38:34 2013 +0100
1.2 +++ b/micropython/__init__.py Sun Jan 13 01:19:41 2013 +0100
1.3 @@ -311,12 +311,12 @@
1.4
1.5 elif isinstance(obj, Class):
1.6
1.7 + full_name = obj.full_name()
1.8 +
1.9 # Prevent ambiguous classes.
1.10
1.11 - full_name = obj.full_name()
1.12 -
1.13 - #if obj.module.has_key(name) and obj.module[name].defines_ambiguous_class():
1.14 - # raise TableGenerationError, "Class %r in module %r is ambiguously defined." % (name, obj.module.full_name())
1.15 + #if obj.module.has_key(obj.name) and obj.module[obj.name].defines_ambiguous_class():
1.16 + # raise TableGenerationError, "Class %r in module %r is ambiguously defined." % (obj.name, obj.module.full_name())
1.17
1.18 # Define a table entry for the class.
1.19
1.20 @@ -329,6 +329,13 @@
1.21 if descendant in all_objects:
1.22 attributes["#" + name] = descendant
1.23
1.24 + # Merge ambiguous classes.
1.25 +
1.26 + if t.has(full_name):
1.27 + old_attributes = t.get(full_name)
1.28 + old_attributes.update(attributes)
1.29 + attributes = old_attributes
1.30 +
1.31 t.add(full_name, attributes)
1.32
1.33 return self.objtable
2.1 --- a/micropython/table.py Sat Jan 12 18:38:34 2013 +0100
2.2 +++ b/micropython/table.py Sun Jan 13 01:19:41 2013 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Preparation of run-time attribute lookup tables.
2.6
2.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -233,6 +233,18 @@
2.13 except KeyError:
2.14 raise TableError, "Name %r is not registered as an attribute in the table." % attrname
2.15
2.16 + def has(self, objname):
2.17 +
2.18 + "Return whether the table has a definition for 'objname'."
2.19 +
2.20 + return self.table.has_key(objname)
2.21 +
2.22 + def get(self, objname):
2.23 +
2.24 + "Return the attributes for 'objname'."
2.25 +
2.26 + return self.table[objname]
2.27 +
2.28 def add(self, objname, attributes):
2.29
2.30 "For the given 'objname' add the given 'attributes' to the table."
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/class_multiple_same_name.py Sun Jan 13 01:19:41 2013 +0100
3.3 @@ -0,0 +1,15 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +class A:
3.7 + x = 1
3.8 +
3.9 +class B(A):
3.10 + y = 2
3.11 +
3.12 +class B(A):
3.13 + z = 3
3.14 +
3.15 +result_1 = A.x
3.16 +result_3 = B.z
3.17 +
3.18 +# vim: tabstop=4 expandtab shiftwidth=4