1.1 --- a/common.py Mon Dec 05 17:19:12 2016 +0100
1.2 +++ b/common.py Mon Dec 05 17:21:35 2016 +0100
1.3 @@ -328,7 +328,7 @@
1.4
1.5 return self.process_structure_node(assignment)
1.6
1.7 - def process_assignment_for_function(self, original_name, source):
1.8 + def process_assignment_for_object(self, original_name, source):
1.9
1.10 """
1.11 Return an assignment operation making 'original_name' refer to the given
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/class_names.py Mon Dec 05 17:21:35 2016 +0100
2.3 @@ -0,0 +1,14 @@
2.4 +class C:
2.5 + pass
2.6 +
2.7 +def c():
2.8 + return 456
2.9 +
2.10 +def f():
2.11 + return C()
2.12 +
2.13 +print f() # 123
2.14 +
2.15 +C = c
2.16 +
2.17 +print f() # 456
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/function_names.py Mon Dec 05 17:21:35 2016 +0100
3.3 @@ -0,0 +1,14 @@
3.4 +def f():
3.5 + return 123
3.6 +
3.7 +def g():
3.8 + return 456
3.9 +
3.10 +def h():
3.11 + return f()
3.12 +
3.13 +print h() # 123
3.14 +
3.15 +f = g
3.16 +
3.17 +print h() # 456
4.1 --- a/translator.py Mon Dec 05 17:19:12 2016 +0100
4.2 +++ b/translator.py Mon Dec 05 17:21:35 2016 +0100
4.3 @@ -774,10 +774,21 @@
4.4
4.5 "Process the given class node 'n'."
4.6
4.7 + class_name = self.get_object_path(n.name)
4.8 +
4.9 + # Where a class is set conditionally or where the name may refer to
4.10 + # different values, assign the name.
4.11 +
4.12 + ref = self.importer.identify(class_name)
4.13 +
4.14 + if not ref.static():
4.15 + self.process_assignment_for_object(
4.16 + n.name, make_expression("((__attr) {0, &%s})" %
4.17 + encode_path(class_name)))
4.18 +
4.19 self.enter_namespace(n.name)
4.20
4.21 if self.have_object():
4.22 - class_name = self.get_namespace_path()
4.23 self.write_comment("Class: %s" % class_name)
4.24
4.25 self.initialise_inherited_members(class_name)
4.26 @@ -800,6 +811,11 @@
4.27 if ref:
4.28 continue
4.29
4.30 + # Ignore special type attributes.
4.31 +
4.32 + if is_type_attribute(name):
4.33 + continue
4.34 +
4.35 # Reference inherited attributes.
4.36
4.37 ref = self.importer.identify(path)
4.38 @@ -941,11 +957,11 @@
4.39 ref = self.importer.identify(objpath)
4.40
4.41 if self.in_conditional or self.in_function:
4.42 - self.process_assignment_for_function(original_name, compiler.ast.Name(name))
4.43 + self.process_assignment_for_object(original_name, compiler.ast.Name(name))
4.44 elif not ref.static():
4.45 context = self.is_method(objpath)
4.46
4.47 - self.process_assignment_for_function(original_name,
4.48 + self.process_assignment_for_object(original_name,
4.49 make_expression("((__attr) {%s, &%s})" % (
4.50 context and "&%s" % encode_path(context) or "0",
4.51 encode_path(objpath))))