Skip to content

Commit 7acfd39

Browse files
author
hartsantler
committed
fixed setting class attribute from an instance (now updates the variable on the instance, not the class)
1 parent 8ef426d commit 7acfd39

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,21 +1434,23 @@ def _visit_assign_helper(self, node, target):
14341434
elif typedef and target.attr in typedef.properties and 'set' in typedef.properties[ target.attr ]:
14351435
setter = typedef.properties[ target.attr ]['set']
14361436
writer.write( '%s( [%s, %s], JSObject() )' %(setter, target_value, self.visit(node.value)) )
1437-
elif typedef and target.attr in typedef.class_attributes:
1438-
writer.write( '''%s['__class__']['%s'] = %s''' %(target_value, target.attr, self.visit(node.value)))
1437+
1438+
#elif typedef and target.attr in typedef.class_attributes:
1439+
# writer.write( '''%s['__class__']['%s'] = %s''' %(target_value, target.attr, self.visit(node.value)))
1440+
14391441
elif typedef and target.attr in typedef.attributes:
14401442
writer.write( '%s.%s = %s' %(target_value, target.attr, self.visit(node.value)))
14411443

14421444
elif typedef and typedef.parents:
14431445
parent_prop = typedef.check_for_parent_with( property=target.attr )
1444-
parent_classattr = typedef.check_for_parent_with( class_attribute=target.attr )
1446+
#parent_classattr = typedef.check_for_parent_with( class_attribute=target.attr )
14451447
parent_setattr = typedef.check_for_parent_with( method='__setattr__' )
14461448
if parent_prop and 'set' in parent_prop.properties[target.attr]:
14471449
setter = parent_prop.properties[target.attr]['set']
14481450
writer.write( '%s( [%s, %s], JSObject() )' %(setter, target_value, self.visit(node.value)) )
14491451

1450-
elif parent_classattr:
1451-
writer.write( "__%s_attrs.%s = %s" %(parent_classattr.name, target.attr, self.visit(node.value)) )
1452+
#elif parent_classattr:
1453+
# writer.write( "__%s_attrs.%s = %s" %(parent_classattr.name, target.attr, self.visit(node.value)) )
14521454

14531455
elif parent_setattr:
14541456
func = parent_setattr.get_pythonjs_function_name( '__setattr__' )

regtests/class/attr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ def main():
2323
getattr(b, 'c')
2424
TestError(not 'No exception: getattr on undefined attribute')
2525
except AttributeError:
26-
pass
26+
pass
27+
28+
b.g = 100
29+
TestError( A.g == 6)

0 commit comments

Comments
 (0)