1.1 --- a/micropython/__init__.py Mon Jun 06 00:48:40 2011 +0200
1.2 +++ b/micropython/__init__.py Wed Jun 08 00:21:12 2011 +0200
1.3 @@ -696,8 +696,21 @@
1.4 # Test for assignment.
1.5
1.6 if attrvalues:
1.7 - for attrvalue in attrvalues:
1.8 - parent.set(attrname, attrvalue, 0)
1.9 +
1.10 + # Instance-related accesses may involve any type
1.11 + # supporting the attribute.
1.12 + # NOTE: Here, an instance actually represents any kind
1.13 + # NOTE: of object.
1.14 +
1.15 + if isinstance(parent, micropython.data.Instance):
1.16 + for attrvalue in attrvalues:
1.17 + for name in objtable.any_possible_objects([attrname]):
1.18 + parent = objtable.access(name, name)
1.19 + if not parent.instance_attributes().has_key(attrname):
1.20 + parent.set(attrname, attrvalue, 0)
1.21 + else:
1.22 + for attrvalue in attrvalues:
1.23 + parent.set(attrname, attrvalue, 0)
1.24
1.25 # Visit attributes of objects known to be used.
1.26
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/attributes_instance_and_class_assignment_external_unknown.py Wed Jun 08 00:21:12 2011 +0200
2.3 @@ -0,0 +1,19 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +class C:
2.7 + def __init__(self):
2.8 + self.a = 0
2.9 +
2.10 +class D:
2.11 + a = 1
2.12 +
2.13 +def f(obj, value):
2.14 + obj.a = value
2.15 +
2.16 +c = C()
2.17 +f(c, 123)
2.18 +f(D, 456)
2.19 +result_123 = c.a
2.20 +result_456 = D.a
2.21 +
2.22 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/attributes_instance_assignment_external.py Wed Jun 08 00:21:12 2011 +0200
3.3 @@ -0,0 +1,11 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +class C:
3.7 + def __init__(self):
3.8 + self.a = 0
3.9 +
3.10 +c = C()
3.11 +c.a = 123
3.12 +result_123 = c.a
3.13 +
3.14 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/attributes_instance_assignment_external_unknown.py Wed Jun 08 00:21:12 2011 +0200
4.3 @@ -0,0 +1,21 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +class C:
4.7 + def __init__(self):
4.8 + self.a = 0
4.9 +
4.10 +class D:
4.11 + def __init__(self):
4.12 + self.a = 1
4.13 +
4.14 +def f(obj, value):
4.15 + obj.a = value
4.16 +
4.17 +c = C()
4.18 +d = D()
4.19 +f(c, 123)
4.20 +f(d, 456)
4.21 +result_123 = c.a
4.22 +result_456 = d.a
4.23 +
4.24 +# vim: tabstop=4 expandtab shiftwidth=4