Python: проинициализированный массив - (в круглых скобках)

Этот коммит содержится в:
Softonik 2022-12-08 05:13:26 +03:00 коммит произвёл Nikolay Kopitonenko
родитель 086f87df05
коммит e5f75d16b7
2 изменённых файлов: 14 добавлений и 9 удалений

Просмотреть файл

@ -137,16 +137,21 @@ func handleBasicLit(bl *ast.BasicLit) string {
} }
func handleCompositeLit(cl *ast.CompositeLit) string { func handleCompositeLit(cl *ast.CompositeLit) string {
code := "[" code := "("
switch cl.Type.(type) { switch len(cl.Elts) {
case *ast.ArrayType: case 0:
args := make([]string, 0) return "[]"
for _, arg := range cl.Elts { default:
args = append(args, handleExpr(arg)) 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 return code
} }

Просмотреть файл

@ -128,7 +128,7 @@ main()
expected := `from skidl import * expected := `from skidl import *
def main(): def main():
a = [1,2,x] a = (1,2,x)
main() main()
` `
Compare(source, expected) Compare(source, expected)