1.1 --- a/templates/ops.c Mon Nov 28 01:00:10 2016 +0100
1.2 +++ b/templates/ops.c Mon Nov 28 15:30:52 2016 +0100
1.3 @@ -172,9 +172,9 @@
1.4
1.5 __attr __test_context(__ref context, __attr attr)
1.6 {
1.7 - /* Preserve any existing instance context. */
1.8 + /* Preserve any existing null or instance context. */
1.9
1.10 - if (__is_instance(attr.context))
1.11 + if ((attr.context == 0) || __is_instance(attr.context))
1.12 return attr;
1.13
1.14 /* Test any instance context against the context employed by the
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/methods_changing.py Mon Nov 28 15:30:52 2016 +0100
2.3 @@ -0,0 +1,28 @@
2.4 +class C:
2.5 + def f(self):
2.6 + return 1
2.7 +
2.8 + def g(self):
2.9 + return self.f()
2.10 +
2.11 +class D(C):
2.12 + pass
2.13 +
2.14 +def f():
2.15 + return 2
2.16 +
2.17 +c = C()
2.18 +d = D()
2.19 +
2.20 +# Invoke a method that calls the default version of f.
2.21 +
2.22 +print c.g() # 1
2.23 +print d.g() # 1
2.24 +
2.25 +# Replace f in C and invoke the method again. For C, f will have changed,
2.26 +# but for D, f will retain its original value.
2.27 +
2.28 +C.f = f
2.29 +
2.30 +print c.g() # 2
2.31 +print d.g() # 1
3.1 --- a/translator.py Mon Nov 28 01:00:10 2016 +0100
3.2 +++ b/translator.py Mon Nov 28 15:30:52 2016 +0100
3.3 @@ -306,7 +306,7 @@
3.4 "Return whether 'path' is a method."
3.5
3.6 class_name, method_name = path.rsplit(".", 1)
3.7 - return self.importer.classes.has_key(class_name) and class_name
3.8 + return self.importer.classes.has_key(class_name) and class_name or None
3.9
3.10 def in_method(self):
3.11
3.12 @@ -890,8 +890,12 @@
3.13 if self.in_conditional or self.in_function:
3.14 self.process_assignment_for_function(original_name, compiler.ast.Name(name))
3.15 elif not ref.static():
3.16 + context = self.is_method(objpath)
3.17 +
3.18 self.process_assignment_for_function(original_name,
3.19 - make_expression("((__attr) {0, &%s})" % encode_path(objpath)))
3.20 + make_expression("((__attr) {%s, &%s})" % (
3.21 + context and "&%s" % encode_path(context) or "0",
3.22 + encode_path(objpath))))
3.23
3.24 def process_function_defaults(self, n, name, instance_name):
3.25