From e5f75d16b76e133e6850153bd3d61704c88c65f9 Mon Sep 17 00:00:00 2001 From: Softonik Date: Thu, 8 Dec 2022 05:13:26 +0300 Subject: [PATCH] =?UTF-8?q?Python:=20=D0=BF=D1=80=D0=BE=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8?= =?UTF-8?q?=D0=B2=20-=20(=D0=B2=20=D0=BA=D1=80=D1=83=D0=B3=D0=BB=D1=8B?= =?UTF-8?q?=D1=85=20=D1=81=D0=BA=D0=BE=D0=B1=D0=BA=D0=B0=D1=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 21 +++++++++++++-------- transpile_python/service_test.go | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) 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)