Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1f7bf0

Browse files
author
hartsantler
committed
go backend: fixed create new instance of class.
1 parent 6ba9c74 commit b1f7bf0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pythonjs/python_to_pythonjs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,11 @@ def visit_Call(self, node):
22922292
args.extend( ['%s=%s'%(x.arg,self.visit(x.value)) for x in node.keywords] )
22932293
if node.starargs:
22942294
args.append('*%s' %self.visit(node.starargs))
2295-
return '%s(%s)' %( self.visit(node.func), ','.join(args) )
2295+
2296+
if isinstance(node.func, Name) and node.func.id in self._js_classes:
2297+
return '__new__%s(%s)' %( self.visit(node.func), ','.join(args) )
2298+
else:
2299+
return '%s(%s)' %( self.visit(node.func), ','.join(args) )
22962300

22972301
elif self._with_js or self._with_dart:
22982302
args = list( map(self.visit, node.args) )

pythonjs/pythonjs_to_go.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def visit_ClassDef(self, node):
4444
out.append('%s %s' %(name, sdef[name]))
4545
out.append('}')
4646

47-
out.append( 'func new_%s() *%s {' %(node.name, node.name))
47+
out.append( 'func __new__%s() *%s {' %(node.name, node.name))
4848
out.append( ' ob := %s{}' %node.name )
4949
out.append( ' ob.__init__()')
5050
out.append( ' return &ob')

regtests/go/class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ def __init__(self):
1111
self.y = 2
1212

1313
def main():
14-
a = new_A()
14+
a = A()
1515
print( a.x )

0 commit comments

Comments
 (0)