@@ -475,7 +475,8 @@ def visit_Assign(self, node):
475475 #writer.write( '''JS('%s( [%s, %s] )')''' %(setter, name, self.visit(node.value)) ) ## can not nest have nested JS() calls
476476 writer .write ( '%s( [%s, %s] )' % (setter , name , self .visit (node .value )) )
477477 fallback = False
478-
478+ else :
479+ writer .write ('#!!!! class is known: %s' % klass )
479480
480481 if fallback :
481482 code = 'set_attribute(%s, "%s", %s)' % (
@@ -492,19 +493,23 @@ def visit_Assign(self, node):
492493 self ._instances [ target .id ] = node .value .func .id ## keep track of instances
493494 elif isinstance (node .value , Call ) and isinstance (node .value .func , Name ) and node .value .func .id in self ._function_return_types :
494495 self ._instances [ target .id ] = self ._function_return_types [ node .value .func .id ]
495- elif target .id in self ._instances :
496- self ._instances .pop ( target .id ) ## TODO is this correct?
497-
498- if isinstance (node .value , Name ): ## if this is a simple copy: "a = b" and "b" is known to be of some class
499- name = self .visit (node .value )
500- if name in self ._instances : self ._instances [ target .id ] = self ._instances [ name ]
501- writer .write ('%s = %s' % (target .id , name ))
496+ elif isinstance (node .value , Call ) and isinstance (node .value .func , Attribute ) and node .value .func .value .id in self ._instances :
497+ typedef = self .get_typedef ( node .value .func .value )
498+ method = node .value .func .attr
499+ if method in typedef .methods :
500+ func = typedef .get_pythonjs_function_name ( method )
501+ if func in self ._function_return_types :
502+ self ._instances [ target .id ] = self ._function_return_types [ func ]
503+
504+ elif isinstance (node .value , Name ) and node_value in self ._instances : ## if this is a simple copy: "a = b" and "b" is known to be of some class
505+ self ._instances [ target .id ] = self ._instances [ node_value ]
502506 elif isinstance (node .value , BinOp ) and hasattr (node .value , 'operator_overloading' ) and node .value .operator_overloading in self ._function_return_types :
503507 self ._instances [ target .id ] = self ._function_return_types [ node .value .operator_overloading ]
504- writer .write ('%s = %s' % (target .id , node_value ))
505508
506- else : ## blind assignment
507- writer .write ('%s = %s' % (target .id , node_value ))
509+ elif target .id in self ._instances :
510+ self ._instances .pop ( target .id )
511+
512+ writer .write ('%s = %s' % (target .id , node_value ))
508513
509514 else : # it's a Tuple
510515 id = self .identifier
0 commit comments