diff --git a/transpile_python/service.go b/transpile_python/service.go index c70a8bb..fa24b80 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -137,16 +137,21 @@ func handleBasicLit(bl *ast.BasicLit) string { } func handleCompositeLit(cl *ast.CompositeLit) string { - code := "[" - switch cl.Type.(type) { - case *ast.ArrayType: - args := make([]string, 0) - for _, arg := range cl.Elts { - args = append(args, handleExpr(arg)) + code := "(" + switch len(cl.Elts) { + case 0: + return "[]" + default: + switch cl.Type.(type) { + case *ast.ArrayType: + args := make([]string, 0) + for _, arg := range cl.Elts { + args = append(args, handleExpr(arg)) + } + code += strings.Join(args, ",") } - code += strings.Join(args, ",") } - code += "]" + code += ")" return code } diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index 111faf8..7f7ed33 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -128,7 +128,7 @@ main() expected := `from skidl import * def main(): - a = [1,2,x] + a = (1,2,x) main() ` Compare(source, expected)