# HG changeset patch # User Paul Boddie # Date 1480185047 -3600 # Node ID e3ec51ee25113a0e503d8015d5e6f71308406bb1 # Parent ab1ac67d78c6b2801d795eff1b8228e50395d4ba Fixed constant instance attributes and added special support for __name__. diff -r ab1ac67d78c6 -r e3ec51ee2511 generator.py --- a/generator.py Sat Nov 26 18:05:47 2016 +0100 +++ b/generator.py Sat Nov 26 19:30:47 2016 +0100 @@ -804,8 +804,8 @@ if self.optimiser.constant_numbers.has_key(attr_path): constant_number = self.optimiser.constant_numbers[attr_path] - constant_value = "const%d" % constant_number - return "{&%s, &%s} /* %s */" % (constant_value, constant_value, name) + constant_value = "__const%d" % constant_number + return "%s /* %s */" % (constant_value, name) # Predefined constant references. @@ -813,6 +813,16 @@ attr_path = encode_predefined_reference("%s.%s" % (path, name)) return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name) + # Special cases. + + if name == "__name__": + local_number = self.importer.all_constants[path][path] + constant_name = "$c%d" % local_number + attr_path = "%s.%s" % (path, constant_name) + constant_number = self.optimiser.constant_numbers[attr_path] + constant_value = "__const%d" % constant_number + return "%s /* %s */" % (constant_value, name) + # General undetermined members. if kind in ("", ""):