From 44c8000250d9a974f727a182c746024a69224367 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 15 Dec 2021 08:51:09 -0800 Subject: [PATCH] feat(python): Generate query code using ASTs instead of templates (#1338) --- examples/python/src/authors/query.py | 2 - examples/python/src/booktest/query.py | 5 +- examples/python/src/jets/query-building.py | 3 - examples/python/src/ondeck/city.py | 3 - examples/python/src/ondeck/venue.py | 5 +- internal/codegen/python/gen.go | 660 ++++- internal/codegen/python/imports.go | 8 +- .../python_postgresql/python/query.py | 4 - .../python_postgresql/python/query.py | 4 - internal/python/ast/ast.pb.go | 2159 ++++++++++++++--- internal/python/poet/builders.go | 90 + internal/python/poet/poet.go | 213 ++ internal/python/printer/printer.go | 304 ++- internal/python/printer/printer_test.go | 20 +- protos/python/ast.proto | 139 +- 15 files changed, 3153 insertions(+), 466 deletions(-) create mode 100644 internal/python/poet/builders.go create mode 100644 internal/python/poet/poet.go diff --git a/examples/python/src/authors/query.py b/examples/python/src/authors/query.py index 5571b49364..d764438121 100644 --- a/examples/python/src/authors/query.py +++ b/examples/python/src/authors/query.py @@ -1,4 +1,3 @@ - # Code generated by sqlc. DO NOT EDIT. from typing import AsyncIterator, Iterator, Optional @@ -108,4 +107,3 @@ async def list_authors(self) -> AsyncIterator[models.Author]: name=row[1], bio=row[2], ) - diff --git a/examples/python/src/booktest/query.py b/examples/python/src/booktest/query.py index 24fc9ded4f..20ffa65be6 100644 --- a/examples/python/src/booktest/query.py +++ b/examples/python/src/booktest/query.py @@ -1,8 +1,7 @@ - # Code generated by sqlc. DO NOT EDIT. -from typing import AsyncIterator, List, Optional import dataclasses import datetime +from typing import AsyncIterator, List, Optional import sqlalchemy import sqlalchemy.ext.asyncio @@ -109,7 +108,6 @@ class CreateBookParams: """ - class AsyncQuerier: def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): self._conn = conn @@ -208,4 +206,3 @@ async def update_book_isbn(self, *, title: str, tags: List[str], book_id: int, i "p3": book_id, "p4": isbn, }) - diff --git a/examples/python/src/jets/query-building.py b/examples/python/src/jets/query-building.py index 0725a80902..d7afd2b8ee 100644 --- a/examples/python/src/jets/query-building.py +++ b/examples/python/src/jets/query-building.py @@ -1,4 +1,3 @@ - # Code generated by sqlc. DO NOT EDIT. from typing import AsyncIterator, Optional @@ -23,7 +22,6 @@ """ - class AsyncQuerier: def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): self._conn = conn @@ -44,4 +42,3 @@ async def list_pilots(self) -> AsyncIterator[models.Pilot]: id=row[0], name=row[1], ) - diff --git a/examples/python/src/ondeck/city.py b/examples/python/src/ondeck/city.py index d7a2123b97..b8e3700d90 100644 --- a/examples/python/src/ondeck/city.py +++ b/examples/python/src/ondeck/city.py @@ -1,4 +1,3 @@ - # Code generated by sqlc. DO NOT EDIT. from typing import AsyncIterator, Optional @@ -40,7 +39,6 @@ """ - class AsyncQuerier: def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): self._conn = conn @@ -73,4 +71,3 @@ async def list_cities(self) -> AsyncIterator[models.City]: async def update_city_name(self, *, slug: str, name: str) -> None: await self._conn.execute(sqlalchemy.text(UPDATE_CITY_NAME), {"p1": slug, "p2": name}) - diff --git a/examples/python/src/ondeck/venue.py b/examples/python/src/ondeck/venue.py index 2d7273da5e..d51f3175b5 100644 --- a/examples/python/src/ondeck/venue.py +++ b/examples/python/src/ondeck/venue.py @@ -1,7 +1,6 @@ - # Code generated by sqlc. DO NOT EDIT. -from typing import AsyncIterator, List, Optional import dataclasses +from typing import AsyncIterator, List, Optional import sqlalchemy import sqlalchemy.ext.asyncio @@ -88,7 +87,6 @@ class VenueCountByCityRow: count: int - class AsyncQuerier: def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): self._conn = conn @@ -156,4 +154,3 @@ async def venue_count_by_city(self) -> AsyncIterator[VenueCountByCityRow]: city=row[0], count=row[1], ) - diff --git a/internal/codegen/python/gen.go b/internal/codegen/python/gen.go index 97633c8e98..5792d58b6d 100644 --- a/internal/codegen/python/gen.go +++ b/internal/codegen/python/gen.go @@ -1,14 +1,11 @@ package python import ( - "bufio" - "bytes" "fmt" "log" "regexp" "sort" "strings" - "text/template" "github.com/kyleconroy/sqlc/internal/codegen" "github.com/kyleconroy/sqlc/internal/compiler" @@ -16,6 +13,7 @@ import ( "github.com/kyleconroy/sqlc/internal/core" "github.com/kyleconroy/sqlc/internal/inflection" pyast "github.com/kyleconroy/sqlc/internal/python/ast" + "github.com/kyleconroy/sqlc/internal/python/poet" pyprint "github.com/kyleconroy/sqlc/internal/python/printer" "github.com/kyleconroy/sqlc/internal/sql/ast" "github.com/kyleconroy/sqlc/internal/sql/catalog" @@ -50,6 +48,17 @@ func (t pyType) String() string { return v } +func (t pyType) Annotation() *pyast.Node { + ann := poet.Name(t.InnerType) + if t.IsArray { + ann = subscriptNode("List", ann) + } + if t.IsNull { + ann = subscriptNode("Optional", ann) + } + return ann +} + type Field struct { Name string Type pyType @@ -70,6 +79,20 @@ type QueryValue struct { Typ pyType } +func (v QueryValue) Annotation() *pyast.Node { + if v.Typ != (pyType{}) { + return v.Typ.Annotation() + } + if v.Struct != nil { + if v.Emit { + return poet.Name(v.Struct.Name) + } else { + return typeRefNode("models", v.Struct.Name) + } + } + panic("no type for QueryValue: " + v.Name) +} + func (v QueryValue) EmitStruct() bool { return v.Emit } @@ -116,6 +139,32 @@ func (v QueryValue) StructRowParser(rowVar string, indentCount int) string { return v.Type() + "(\n" + strings.Join(params, "\n") + "\n" + indent + ")" } +func (v QueryValue) RowNode(rowVar string) *pyast.Node { + if !v.IsStruct() { + return subscriptNode( + rowVar, + constantInt(0), + ) + } + call := &pyast.Call{ + Func: v.Annotation(), + } + for i, f := range v.Struct.Fields { + call.Keywords = append(call.Keywords, &pyast.Keyword{ + Arg: f.Name, + Value: subscriptNode( + rowVar, + constantInt(i), + ), + }) + } + return &pyast.Node{ + Node: &pyast.Node_Call{ + Call: call, + }, + } +} + // A struct used to generate methods and fields on the Queries struct type Query struct { Cmd string @@ -144,6 +193,23 @@ func (q Query) ArgPairs() string { return ", *, " + strings.Join(argPairs, ", ") } +func (q Query) AddArgs(args *pyast.Arguments) { + // A single struct arg does not need to be passed as a keyword argument + if len(q.Args) == 1 && q.Args[0].IsStruct() { + args.Args = append(args.Args, &pyast.Arg{ + Arg: q.Args[0].Name, + Annotation: q.Args[0].Annotation(), + }) + return + } + for _, a := range q.Args { + args.KwOnlyArgs = append(args.KwOnlyArgs, &pyast.Arg{ + Arg: a.Name, + Annotation: a.Annotation(), + }) + } +} + func (q Query) ArgDict() string { params := make([]string, 0, len(q.Args)) i := 1 @@ -170,6 +236,35 @@ func (q Query) ArgDict() string { return ", {\n " + strings.Join(params, ",\n ") + ",\n }" } +func (q Query) ArgDictNode() *pyast.Node { + dict := &pyast.Dict{} + i := 1 + for _, a := range q.Args { + if a.isEmpty() { + continue + } + if a.IsStruct() { + for _, f := range a.Struct.Fields { + dict.Keys = append(dict.Keys, poet.Constant(fmt.Sprintf("p%v", i))) + dict.Values = append(dict.Values, typeRefNode(a.Name, f.Name)) + i++ + } + } else { + dict.Keys = append(dict.Keys, poet.Constant(fmt.Sprintf("p%v", i))) + dict.Values = append(dict.Values, poet.Name(a.Name)) + i++ + } + } + if len(dict.Keys) == 0 { + return nil + } + return &pyast.Node{ + Node: &pyast.Node_Dict{ + Dict: dict, + }, + } +} + func makePyType(r *compiler.Result, col *compiler.Column, settings config.CombinedSettings) pyType { typ := pyInnerType(r, col, settings) return pyType{ @@ -483,15 +578,6 @@ func buildQueries(r *compiler.Result, settings config.CombinedSettings, structs sort.Slice(qs, func(i, j int) bool { return qs[i].MethodName < qs[j].MethodName }) return qs } -func aliasNode(name string) *pyast.Node { - return &pyast.Node{ - Node: &pyast.Node_Alias{ - Alias: &pyast.Alias{ - Name: name, - }, - }, - } -} func importNode(name string) *pyast.Node { return &pyast.Node{ @@ -522,50 +608,126 @@ func classDefNode(name string, bases ...*pyast.Node) *pyast.Node { } } -func nameNode(id string) *pyast.Node { +func assignNode(target string, value *pyast.Node) *pyast.Node { + return &pyast.Node{ + Node: &pyast.Node_Assign{ + Assign: &pyast.Assign{ + Targets: []*pyast.Node{ + poet.Name(target), + }, + Value: value, + }, + }, + } +} + +func constantInt(value int) *pyast.Node { return &pyast.Node{ - Node: &pyast.Node_Name{ - Name: &pyast.Name{Id: id}, + Node: &pyast.Node_Constant{ + Constant: &pyast.Constant{ + Value: &pyast.Constant_Int{ + Int: int32(value), + }, + }, }, } } -func attributeNode(value, attr string) *pyast.Node { +func subscriptNode(value string, slice *pyast.Node) *pyast.Node { return &pyast.Node{ - Node: &pyast.Node_Attribute{ - Attribute: &pyast.Attribute{ + Node: &pyast.Node_Subscript{ + Subscript: &pyast.Subscript{ Value: &pyast.Name{Id: value}, - Attr: attr, + Slice: slice, }, }, } } -func assignNode(target, value string) *pyast.Node { - return &pyast.Node{ - Node: &pyast.Node_Assign{ - Assign: &pyast.Assign{ - Targets: []*pyast.Name{ - {Id: target}, +func dataclassNode(name string) *pyast.ClassDef { + return &pyast.ClassDef{ + Name: name, + DecoratorList: []*pyast.Node{ + { + Node: &pyast.Node_Call{ + Call: &pyast.Call{ + Func: poet.Attribute(poet.Name("dataclasses"), "dataclass"), + }, }, - Value: &pyast.Node{ - Node: &pyast.Node_Constant{ - Constant: &pyast.Constant{ - Value: value, - }, + }, + }, + } +} + +func fieldNode(f Field) *pyast.Node { + return &pyast.Node{ + Node: &pyast.Node_AnnAssign{ + AnnAssign: &pyast.AnnAssign{ + Target: &pyast.Name{Id: f.Name}, + Annotation: f.Type.Annotation(), + Comment: f.Comment, + }, + }, + } +} + +func typeRefNode(base string, parts ...string) *pyast.Node { + n := poet.Name(base) + for _, p := range parts { + n = poet.Attribute(n, p) + } + return n +} + +func connMethodNode(method, name string, arg *pyast.Node) *pyast.Node { + args := []*pyast.Node{ + { + Node: &pyast.Node_Call{ + Call: &pyast.Call{ + Func: typeRefNode("sqlalchemy", "text"), + Args: []*pyast.Node{ + poet.Name(name), }, }, }, }, } + if arg != nil { + args = append(args, arg) + } + return &pyast.Node{ + Node: &pyast.Node_Call{ + Call: &pyast.Call{ + Func: typeRefNode("self", "_conn", method), + Args: args, + }, + }, + } } -func subscriptNode(value string, slice *pyast.Node) *pyast.Node { +func buildImportGroup(specs map[string]importSpec) *pyast.Node { + var body []*pyast.Node + for _, spec := range buildImportBlock2(specs) { + if len(spec.Names) > 0 && spec.Names[0] != "" { + imp := &pyast.ImportFrom{ + Module: spec.Module, + } + for _, name := range spec.Names { + imp.Names = append(imp.Names, poet.Alias(name)) + } + body = append(body, &pyast.Node{ + Node: &pyast.Node_ImportFrom{ + ImportFrom: imp, + }, + }) + } else { + body = append(body, importNode(spec.Module)) + } + } return &pyast.Node{ - Node: &pyast.Node_Subscript{ - Subscript: &pyast.Subscript{ - Value: &pyast.Name{Id: value}, - Slice: slice, + Node: &pyast.Node_ImportGroup{ + ImportGroup: &pyast.ImportGroup{ + Imports: body, }, }, } @@ -583,53 +745,29 @@ func buildModelsTree(ctx *pyTmplCtx, i *importer) *pyast.Node { }, }, } - std, pkg := i.modelImportSpecs() - for _, specs := range []map[string]importSpec{std, pkg} { - for _, spec := range buildImportBlock2(specs) { - if len(spec.Names) > 0 && spec.Names[0] != "" { - imp := &pyast.ImportFrom{ - Module: spec.Module, - } - for _, name := range spec.Names { - imp.Names = append(imp.Names, aliasNode(name)) - } - mod.Body = append(mod.Body, &pyast.Node{ - Node: &pyast.Node_ImportFrom{ - ImportFrom: imp, - }, - }) - } else { - mod.Body = append(mod.Body, importNode(spec.Module)) - } - } - } + std, pkg := i.modelImportSpecs() + mod.Body = append(mod.Body, buildImportGroup(std), buildImportGroup(pkg)) for _, e := range ctx.Enums { def := &pyast.ClassDef{ Name: e.Name, Bases: []*pyast.Node{ - nameNode("str"), - attributeNode("enum", "Enum"), + poet.Name("str"), + poet.Attribute(poet.Name("enum"), "Enum"), }, } if e.Comment != "" { def.Body = append(def.Body, &pyast.Node{ Node: &pyast.Node_Expr{ Expr: &pyast.Expr{ - Value: &pyast.Node{ - Node: &pyast.Node_Constant{ - Constant: &pyast.Constant{ - Value: e.Comment, - }, - }, - }, + Value: poet.Constant(e.Comment), }, }, }) } for _, c := range e.Constants { - def.Body = append(def.Body, assignNode(c.Name, c.Value)) + def.Body = append(def.Body, assignNode(c.Name, poet.Constant(c.Value))) } mod.Body = append(mod.Body, &pyast.Node{ Node: &pyast.Node_ClassDef{ @@ -639,50 +777,18 @@ func buildModelsTree(ctx *pyTmplCtx, i *importer) *pyast.Node { } for _, m := range ctx.Models { - def := &pyast.ClassDef{ - Name: m.Name, - DecoratorList: []*pyast.Node{ - { - Node: &pyast.Node_Call{ - Call: &pyast.Call{ - Func: attributeNode("dataclasses", "dataclass"), - }, - }, - }, - }, - } + def := dataclassNode(m.Name) if m.Comment != "" { def.Body = append(def.Body, &pyast.Node{ Node: &pyast.Node_Expr{ Expr: &pyast.Expr{ - Value: &pyast.Node{ - Node: &pyast.Node_Constant{ - Constant: &pyast.Constant{ - Value: m.Comment, - }, - }, - }, + Value: poet.Constant(m.Comment), }, }, }) } for _, f := range m.Fields { - ann := nameNode(f.Type.InnerType) - if f.Type.IsArray { - ann = subscriptNode("List", ann) - } - if f.Type.IsNull { - ann = subscriptNode("Optional", ann) - } - def.Body = append(def.Body, &pyast.Node{ - Node: &pyast.Node_AnnAssign{ - AnnAssign: &pyast.AnnAssign{ - Target: &pyast.Name{Id: f.Name}, - Annotation: ann, - Comment: f.Comment, - }, - }, - }) + def.Body = append(def.Body, fieldNode(f)) } mod.Body = append(mod.Body, &pyast.Node{ Node: &pyast.Node_ClassDef{ @@ -694,6 +800,324 @@ func buildModelsTree(ctx *pyTmplCtx, i *importer) *pyast.Node { return &pyast.Node{Node: &pyast.Node_Module{Module: mod}} } +func querierClassDef() *pyast.ClassDef { + return &pyast.ClassDef{ + Name: "Querier", + Body: []*pyast.Node{ + { + Node: &pyast.Node_FunctionDef{ + FunctionDef: &pyast.FunctionDef{ + Name: "__init__", + Args: &pyast.Arguments{ + Args: []*pyast.Arg{ + { + Arg: "self", + }, + { + Arg: "conn", + Annotation: typeRefNode("sqlalchemy", "engine", "Connection"), + }, + }, + }, + Body: []*pyast.Node{ + { + Node: &pyast.Node_Assign{ + Assign: &pyast.Assign{ + Targets: []*pyast.Node{ + poet.Attribute(poet.Name("self"), "_conn"), + }, + Value: poet.Name("conn"), + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func asyncQuerierClassDef() *pyast.ClassDef { + return &pyast.ClassDef{ + Name: "AsyncQuerier", + Body: []*pyast.Node{ + { + Node: &pyast.Node_FunctionDef{ + FunctionDef: &pyast.FunctionDef{ + Name: "__init__", + Args: &pyast.Arguments{ + Args: []*pyast.Arg{ + { + Arg: "self", + }, + { + Arg: "conn", + Annotation: typeRefNode("sqlalchemy", "ext", "asyncio", "AsyncConnection"), + }, + }, + }, + Body: []*pyast.Node{ + { + Node: &pyast.Node_Assign{ + Assign: &pyast.Assign{ + Targets: []*pyast.Node{ + poet.Attribute(poet.Name("self"), "_conn"), + }, + Value: poet.Name("conn"), + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func buildQueryTree(ctx *pyTmplCtx, i *importer, source string) *pyast.Node { + mod := &pyast.Module{ + Body: []*pyast.Node{ + poet.Comment( + "Code generated by sqlc. DO NOT EDIT.", + ), + }, + } + + std, pkg := i.queryImportSpecs(source) + mod.Body = append(mod.Body, buildImportGroup(std), buildImportGroup(pkg)) + mod.Body = append(mod.Body, &pyast.Node{ + Node: &pyast.Node_ImportGroup{ + ImportGroup: &pyast.ImportGroup{ + Imports: []*pyast.Node{ + { + Node: &pyast.Node_ImportFrom{ + ImportFrom: &pyast.ImportFrom{ + Module: i.Settings.Python.Package, + Names: []*pyast.Node{ + poet.Alias("models"), + }, + }, + }, + }, + }, + }, + }, + }) + + for _, q := range ctx.Queries { + if !ctx.OutputQuery(q.SourceName) { + continue + } + queryText := fmt.Sprintf("-- name: %s \\\\%s\n%s\n", q.MethodName, q.Cmd, q.SQL) + mod.Body = append(mod.Body, assignNode(q.ConstantName, poet.Constant(queryText))) + for _, arg := range q.Args { + if arg.EmitStruct() { + def := dataclassNode(arg.Type()) + for _, f := range arg.Struct.Fields { + def.Body = append(def.Body, fieldNode(f)) + } + mod.Body = append(mod.Body, poet.Node(def)) + } + } + if q.Ret.EmitStruct() { + def := dataclassNode(q.Ret.Type()) + for _, f := range q.Ret.Struct.Fields { + def.Body = append(def.Body, fieldNode(f)) + } + mod.Body = append(mod.Body, poet.Node(def)) + } + } + + if ctx.EmitSync { + cls := querierClassDef() + for _, q := range ctx.Queries { + if !ctx.OutputQuery(q.SourceName) { + continue + } + f := &pyast.FunctionDef{ + Name: q.MethodName, + Args: &pyast.Arguments{ + Args: []*pyast.Arg{ + { + Arg: "self", + }, + }, + }, + } + + q.AddArgs(f.Args) + exec := connMethodNode("execute", q.ConstantName, q.ArgDictNode()) + + switch q.Cmd { + case ":one": + f.Body = append(f.Body, + assignNode("row", poet.Node( + &pyast.Call{ + Func: poet.Attribute(exec, "first"), + }, + )), + poet.Node( + &pyast.If{ + Test: poet.Node( + &pyast.Compare{ + Left: poet.Name("row"), + Ops: []*pyast.Node{ + poet.Is(), + }, + Comparators: []*pyast.Node{ + poet.Constant(nil), + }, + }, + ), + Body: []*pyast.Node{ + poet.Return( + poet.Constant(nil), + ), + }, + }, + ), + poet.Return(q.Ret.RowNode("row")), + ) + f.Returns = subscriptNode("Optional", q.Ret.Annotation()) + case ":many": + f.Body = append(f.Body, + assignNode("result", exec), + poet.Node( + &pyast.For{ + Target: poet.Name("row"), + Iter: poet.Name("result"), + Body: []*pyast.Node{ + poet.Expr( + poet.Yield( + q.Ret.RowNode("row"), + ), + ), + }, + }, + ), + ) + f.Returns = subscriptNode("Iterator", q.Ret.Annotation()) + case ":exec": + f.Body = append(f.Body, exec) + f.Returns = poet.Constant(nil) + case ":execrows": + f.Body = append(f.Body, + assignNode("result", exec), + poet.Return(poet.Attribute(poet.Name("result"), "rowcount")), + ) + f.Returns = poet.Name("int") + case ":execresult": + f.Body = append(f.Body, + poet.Return(exec), + ) + f.Returns = typeRefNode("sqlalchemy", "engine", "Result") + default: + panic("unknown cmd " + q.Cmd) + } + + cls.Body = append(cls.Body, poet.Node(f)) + } + mod.Body = append(mod.Body, poet.Node(cls)) + } + + if ctx.EmitAsync { + cls := asyncQuerierClassDef() + for _, q := range ctx.Queries { + if !ctx.OutputQuery(q.SourceName) { + continue + } + f := &pyast.AsyncFunctionDef{ + Name: q.MethodName, + Args: &pyast.Arguments{ + Args: []*pyast.Arg{ + { + Arg: "self", + }, + }, + }, + } + + q.AddArgs(f.Args) + exec := connMethodNode("execute", q.ConstantName, q.ArgDictNode()) + + switch q.Cmd { + case ":one": + f.Body = append(f.Body, + assignNode("row", poet.Node( + &pyast.Call{ + Func: poet.Attribute(poet.Await(exec), "first"), + }, + )), + poet.Node( + &pyast.If{ + Test: poet.Node( + &pyast.Compare{ + Left: poet.Name("row"), + Ops: []*pyast.Node{ + poet.Is(), + }, + Comparators: []*pyast.Node{ + poet.Constant(nil), + }, + }, + ), + Body: []*pyast.Node{ + poet.Return( + poet.Constant(nil), + ), + }, + }, + ), + poet.Return(q.Ret.RowNode("row")), + ) + f.Returns = subscriptNode("Optional", q.Ret.Annotation()) + case ":many": + stream := connMethodNode("stream", q.ConstantName, q.ArgDictNode()) + f.Body = append(f.Body, + assignNode("result", poet.Await(stream)), + poet.Node( + &pyast.AsyncFor{ + Target: poet.Name("row"), + Iter: poet.Name("result"), + Body: []*pyast.Node{ + poet.Expr( + poet.Yield( + q.Ret.RowNode("row"), + ), + ), + }, + }, + ), + ) + f.Returns = subscriptNode("AsyncIterator", q.Ret.Annotation()) + case ":exec": + f.Body = append(f.Body, poet.Await(exec)) + f.Returns = poet.Constant(nil) + case ":execrows": + f.Body = append(f.Body, + assignNode("result", poet.Await(exec)), + poet.Return(poet.Attribute(poet.Name("result"), "rowcount")), + ) + f.Returns = poet.Name("int") + case ":execresult": + f.Body = append(f.Body, + poet.Return(poet.Await(exec)), + ) + f.Returns = typeRefNode("sqlalchemy", "engine", "Result") + default: + panic("unknown cmd " + q.Cmd) + } + + cls.Body = append(cls.Body, poet.Node(f)) + } + mod.Body = append(mod.Body, poet.Node(cls)) + } + + return poet.Node(mod) +} + var queriesTmpl = ` {{- define "dataclassParse"}} @@ -853,14 +1277,6 @@ func Generate(r *compiler.Result, settings config.CombinedSettings) (map[string] Enums: enums, } - funcMap := template.FuncMap{ - "lowerTitle": codegen.LowerTitle, - "comment": HashComment, - "imports": i.Imports, - } - - queriesFile := template.Must(template.New("table").Funcs(funcMap).Parse(queriesTmpl)) - tctx := pyTmplCtx{ Models: models, Queries: queries, @@ -870,25 +1286,8 @@ func Generate(r *compiler.Result, settings config.CombinedSettings) (map[string] } output := map[string]string{} - - execute := func(name string, t *template.Template) error { - var b bytes.Buffer - w := bufio.NewWriter(&b) - tctx.SourceName = name - err := t.Execute(w, &tctx) - w.Flush() - if err != nil { - return err - } - if !strings.HasSuffix(name, ".py") { - name = strings.TrimSuffix(name, ".sql") - name += ".py" - } - output[name] = b.String() - return nil - } - result := pyprint.Print(buildModelsTree(&tctx, i), pyprint.Options{}) + tctx.SourceName = "models.py" output["models.py"] = string(result.Python) files := map[string]struct{}{} @@ -897,9 +1296,14 @@ func Generate(r *compiler.Result, settings config.CombinedSettings) (map[string] } for source := range files { - if err := execute(source, queriesFile); err != nil { - return nil, err + tctx.SourceName = source + result := pyprint.Print(buildQueryTree(&tctx, i, source), pyprint.Options{}) + name := source + if !strings.HasSuffix(name, ".py") { + name = strings.TrimSuffix(name, ".sql") + name += ".py" } + output[name] = string(result.Python) } return output, nil diff --git a/internal/codegen/python/imports.go b/internal/codegen/python/imports.go index 4947e52840..d46da05e3a 100644 --- a/internal/codegen/python/imports.go +++ b/internal/codegen/python/imports.go @@ -115,7 +115,7 @@ func (i *importer) modelImports() []string { return importLines } -func (i *importer) queryImports(fileName string) []string { +func (i *importer) queryImportSpecs(fileName string) (map[string]importSpec, map[string]importSpec) { queryUses := func(name string) bool { for _, q := range i.Queries { if q.SourceName != fileName { @@ -176,6 +176,12 @@ func (i *importer) queryImports(fileName string) []string { } } + return std, pkg +} + +func (i *importer) queryImports(fileName string) []string { + std, pkg := i.queryImportSpecs(fileName) + modelImportStr := fmt.Sprintf("from %s import models", i.Settings.Python.Package) importLines := []string{ diff --git a/internal/endtoend/testdata/exec_result/python_postgresql/python/query.py b/internal/endtoend/testdata/exec_result/python_postgresql/python/query.py index 371c0391c6..1de523d8e7 100644 --- a/internal/endtoend/testdata/exec_result/python_postgresql/python/query.py +++ b/internal/endtoend/testdata/exec_result/python_postgresql/python/query.py @@ -1,7 +1,4 @@ - # Code generated by sqlc. DO NOT EDIT. - - import sqlalchemy import sqlalchemy.ext.asyncio @@ -27,4 +24,3 @@ def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): async def delete_bar_by_id(self, *, id: int) -> sqlalchemy.engine.Result: return await self._conn.execute(sqlalchemy.text(DELETE_BAR_BY_ID), {"p1": id}) - diff --git a/internal/endtoend/testdata/exec_rows/python_postgresql/python/query.py b/internal/endtoend/testdata/exec_rows/python_postgresql/python/query.py index 720acd24ee..fef4752418 100644 --- a/internal/endtoend/testdata/exec_rows/python_postgresql/python/query.py +++ b/internal/endtoend/testdata/exec_rows/python_postgresql/python/query.py @@ -1,7 +1,4 @@ - # Code generated by sqlc. DO NOT EDIT. - - import sqlalchemy import sqlalchemy.ext.asyncio @@ -29,4 +26,3 @@ def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): async def delete_bar_by_id(self, *, id: int) -> int: result = await self._conn.execute(sqlalchemy.text(DELETE_BAR_BY_ID), {"p1": id}) return result.rowcount - diff --git a/internal/python/ast/ast.pb.go b/internal/python/ast/ast.pb.go index f32295bb59..eace165baa 100644 --- a/internal/python/ast/ast.pb.go +++ b/internal/python/ast/ast.pb.go @@ -40,6 +40,22 @@ type Node struct { // *Node_Comment // *Node_Expr // *Node_Call + // *Node_FunctionDef + // *Node_Arg + // *Node_Arguments + // *Node_AsyncFunctionDef + // *Node_Pass + // *Node_Dict + // *Node_If + // *Node_Compare + // *Node_Return + // *Node_Is + // *Node_Keyword + // *Node_Yield + // *Node_For + // *Node_Await + // *Node_AsyncFor + // *Node_ImportGroup Node isNode_Node `protobuf_oneof:"node"` } @@ -180,6 +196,118 @@ func (x *Node) GetCall() *Call { return nil } +func (x *Node) GetFunctionDef() *FunctionDef { + if x, ok := x.GetNode().(*Node_FunctionDef); ok { + return x.FunctionDef + } + return nil +} + +func (x *Node) GetArg() *Arg { + if x, ok := x.GetNode().(*Node_Arg); ok { + return x.Arg + } + return nil +} + +func (x *Node) GetArguments() *Arguments { + if x, ok := x.GetNode().(*Node_Arguments); ok { + return x.Arguments + } + return nil +} + +func (x *Node) GetAsyncFunctionDef() *AsyncFunctionDef { + if x, ok := x.GetNode().(*Node_AsyncFunctionDef); ok { + return x.AsyncFunctionDef + } + return nil +} + +func (x *Node) GetPass() *Pass { + if x, ok := x.GetNode().(*Node_Pass); ok { + return x.Pass + } + return nil +} + +func (x *Node) GetDict() *Dict { + if x, ok := x.GetNode().(*Node_Dict); ok { + return x.Dict + } + return nil +} + +func (x *Node) GetIf() *If { + if x, ok := x.GetNode().(*Node_If); ok { + return x.If + } + return nil +} + +func (x *Node) GetCompare() *Compare { + if x, ok := x.GetNode().(*Node_Compare); ok { + return x.Compare + } + return nil +} + +func (x *Node) GetReturn() *Return { + if x, ok := x.GetNode().(*Node_Return); ok { + return x.Return + } + return nil +} + +func (x *Node) GetIs() *Is { + if x, ok := x.GetNode().(*Node_Is); ok { + return x.Is + } + return nil +} + +func (x *Node) GetKeyword() *Keyword { + if x, ok := x.GetNode().(*Node_Keyword); ok { + return x.Keyword + } + return nil +} + +func (x *Node) GetYield() *Yield { + if x, ok := x.GetNode().(*Node_Yield); ok { + return x.Yield + } + return nil +} + +func (x *Node) GetFor() *For { + if x, ok := x.GetNode().(*Node_For); ok { + return x.For + } + return nil +} + +func (x *Node) GetAwait() *Await { + if x, ok := x.GetNode().(*Node_Await); ok { + return x.Await + } + return nil +} + +func (x *Node) GetAsyncFor() *AsyncFor { + if x, ok := x.GetNode().(*Node_AsyncFor); ok { + return x.AsyncFor + } + return nil +} + +func (x *Node) GetImportGroup() *ImportGroup { + if x, ok := x.GetNode().(*Node_ImportGroup); ok { + return x.ImportGroup + } + return nil +} + type isNode_Node interface { isNode_Node() } @@ -240,6 +368,70 @@ type Node_Call struct { Call *Call `protobuf:"bytes,14,opt,name=call,json=Call,proto3,oneof"` } +type Node_FunctionDef struct { + FunctionDef *FunctionDef `protobuf:"bytes,15,opt,name=function_def,json=FunctionDef,proto3,oneof"` +} + +type Node_Arg struct { + Arg *Arg `protobuf:"bytes,16,opt,name=arg,json=Arg,proto3,oneof"` +} + +type Node_Arguments struct { + Arguments *Arguments `protobuf:"bytes,17,opt,name=arguments,json=Arguments,proto3,oneof"` +} + +type Node_AsyncFunctionDef struct { + AsyncFunctionDef *AsyncFunctionDef `protobuf:"bytes,18,opt,name=async_function_def,json=AsyncFunctionDef,proto3,oneof"` +} + +type Node_Pass struct { + Pass *Pass `protobuf:"bytes,19,opt,name=pass,json=Pass,proto3,oneof"` +} + +type Node_Dict struct { + Dict *Dict `protobuf:"bytes,20,opt,name=dict,json=Dict,proto3,oneof"` +} + +type Node_If struct { + If *If `protobuf:"bytes,21,opt,name=if,json=If,proto3,oneof"` +} + +type Node_Compare struct { + Compare *Compare `protobuf:"bytes,22,opt,name=compare,json=Compare,proto3,oneof"` +} + +type Node_Return struct { + Return *Return `protobuf:"bytes,23,opt,name=return,json=Return,proto3,oneof"` +} + +type Node_Is struct { + Is *Is `protobuf:"bytes,24,opt,name=is,json=Is,proto3,oneof"` +} + +type Node_Keyword struct { + Keyword *Keyword `protobuf:"bytes,25,opt,name=keyword,json=Keyword,proto3,oneof"` +} + +type Node_Yield struct { + Yield *Yield `protobuf:"bytes,26,opt,name=yield,json=Yield,proto3,oneof"` +} + +type Node_For struct { + For *For `protobuf:"bytes,27,opt,name=for,json=For,proto3,oneof"` +} + +type Node_Await struct { + Await *Await `protobuf:"bytes,28,opt,name=await,json=Await,proto3,oneof"` +} + +type Node_AsyncFor struct { + AsyncFor *AsyncFor `protobuf:"bytes,29,opt,name=async_for,json=AsyncFor,proto3,oneof"` +} + +type Node_ImportGroup struct { + ImportGroup *ImportGroup `protobuf:"bytes,30,opt,name=import_group,json=ImportGroup,proto3,oneof"` +} + func (*Node_ClassDef) isNode_Node() {} func (*Node_Import) isNode_Node() {} @@ -268,6 +460,38 @@ func (*Node_Expr) isNode_Node() {} func (*Node_Call) isNode_Node() {} +func (*Node_FunctionDef) isNode_Node() {} + +func (*Node_Arg) isNode_Node() {} + +func (*Node_Arguments) isNode_Node() {} + +func (*Node_AsyncFunctionDef) isNode_Node() {} + +func (*Node_Pass) isNode_Node() {} + +func (*Node_Dict) isNode_Node() {} + +func (*Node_If) isNode_Node() {} + +func (*Node_Compare) isNode_Node() {} + +func (*Node_Return) isNode_Node() {} + +func (*Node_Is) isNode_Node() {} + +func (*Node_Keyword) isNode_Node() {} + +func (*Node_Yield) isNode_Node() {} + +func (*Node_For) isNode_Node() {} + +func (*Node_Await) isNode_Node() {} + +func (*Node_AsyncFor) isNode_Node() {} + +func (*Node_ImportGroup) isNode_Node() {} + type Alias struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -315,19 +539,66 @@ func (x *Alias) GetName() string { return "" } +type Await struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Await) Reset() { + *x = Await{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Await) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Await) ProtoMessage() {} + +func (x *Await) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Await.ProtoReflect.Descriptor instead. +func (*Await) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{2} +} + +func (x *Await) GetValue() *Node { + if x != nil { + return x.Value + } + return nil +} + type Attribute struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Value *Name `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` Attr string `protobuf:"bytes,2,opt,name=attr,proto3" json:"attr,omitempty"` } func (x *Attribute) Reset() { *x = Attribute{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[2] + mi := &file_python_ast_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -340,7 +611,7 @@ func (x *Attribute) String() string { func (*Attribute) ProtoMessage() {} func (x *Attribute) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[2] + mi := &file_python_ast_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -353,10 +624,10 @@ func (x *Attribute) ProtoReflect() protoreflect.Message { // Deprecated: Use Attribute.ProtoReflect.Descriptor instead. func (*Attribute) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{2} + return file_python_ast_proto_rawDescGZIP(), []int{3} } -func (x *Attribute) GetValue() *Name { +func (x *Attribute) GetValue() *Node { if x != nil { return x.Value } @@ -384,7 +655,7 @@ type AnnAssign struct { func (x *AnnAssign) Reset() { *x = AnnAssign{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[3] + mi := &file_python_ast_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -397,7 +668,7 @@ func (x *AnnAssign) String() string { func (*AnnAssign) ProtoMessage() {} func (x *AnnAssign) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[3] + mi := &file_python_ast_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -410,7 +681,7 @@ func (x *AnnAssign) ProtoReflect() protoreflect.Message { // Deprecated: Use AnnAssign.ProtoReflect.Descriptor instead. func (*AnnAssign) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{3} + return file_python_ast_proto_rawDescGZIP(), []int{4} } func (x *AnnAssign) GetTarget() *Name { @@ -441,33 +712,32 @@ func (x *AnnAssign) GetComment() string { return "" } -type Assign struct { +type Arg struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Targets []*Name `protobuf:"bytes,1,rep,name=targets,proto3" json:"targets,omitempty"` - Value *Node `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - Comment string `protobuf:"bytes,3,opt,name=Comment,json=comment,proto3" json:"Comment,omitempty"` + Arg string `protobuf:"bytes,1,opt,name=arg,proto3" json:"arg,omitempty"` + Annotation *Node `protobuf:"bytes,2,opt,name=annotation,proto3" json:"annotation,omitempty"` } -func (x *Assign) Reset() { - *x = Assign{} +func (x *Arg) Reset() { + *x = Arg{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[4] + mi := &file_python_ast_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Assign) String() string { +func (x *Arg) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Assign) ProtoMessage() {} +func (*Arg) ProtoMessage() {} -func (x *Assign) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[4] +func (x *Arg) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -478,57 +748,51 @@ func (x *Assign) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Assign.ProtoReflect.Descriptor instead. -func (*Assign) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{4} +// Deprecated: Use Arg.ProtoReflect.Descriptor instead. +func (*Arg) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{5} } -func (x *Assign) GetTargets() []*Name { +func (x *Arg) GetArg() string { if x != nil { - return x.Targets + return x.Arg } - return nil + return "" } -func (x *Assign) GetValue() *Node { +func (x *Arg) GetAnnotation() *Node { if x != nil { - return x.Value + return x.Annotation } return nil } -func (x *Assign) GetComment() string { - if x != nil { - return x.Comment - } - return "" -} - -type Call struct { +type Arguments struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Func *Node `protobuf:"bytes,1,opt,name=func,proto3" json:"func,omitempty"` + Args []*Arg `protobuf:"bytes,1,rep,name=args,proto3" json:"args,omitempty"` + KwOnlyArgs []*Arg `protobuf:"bytes,2,rep,name=kw_only_args,json=kwonlyargs,proto3" json:"kw_only_args,omitempty"` } -func (x *Call) Reset() { - *x = Call{} +func (x *Arguments) Reset() { + *x = Arguments{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[5] + mi := &file_python_ast_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Call) String() string { +func (x *Arguments) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Call) ProtoMessage() {} +func (*Arguments) ProtoMessage() {} -func (x *Call) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[5] +func (x *Arguments) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -539,47 +803,52 @@ func (x *Call) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Call.ProtoReflect.Descriptor instead. -func (*Call) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{5} +// Deprecated: Use Arguments.ProtoReflect.Descriptor instead. +func (*Arguments) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{6} } -func (x *Call) GetFunc() *Node { +func (x *Arguments) GetArgs() []*Arg { if x != nil { - return x.Func + return x.Args } return nil } -type ClassDef struct { +func (x *Arguments) GetKwOnlyArgs() []*Arg { + if x != nil { + return x.KwOnlyArgs + } + return nil +} + +type AsyncFor struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Bases []*Node `protobuf:"bytes,2,rep,name=bases,proto3" json:"bases,omitempty"` - Keywords []*Node `protobuf:"bytes,3,rep,name=keywords,proto3" json:"keywords,omitempty"` - Body []*Node `protobuf:"bytes,4,rep,name=body,proto3" json:"body,omitempty"` - DecoratorList []*Node `protobuf:"bytes,5,rep,name=decorator_list,proto3" json:"decorator_list,omitempty"` + Target *Node `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` + Iter *Node `protobuf:"bytes,2,opt,name=iter,proto3" json:"iter,omitempty"` + Body []*Node `protobuf:"bytes,3,rep,name=body,proto3" json:"body,omitempty"` } -func (x *ClassDef) Reset() { - *x = ClassDef{} +func (x *AsyncFor) Reset() { + *x = AsyncFor{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[6] + mi := &file_python_ast_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *ClassDef) String() string { +func (x *AsyncFor) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ClassDef) ProtoMessage() {} +func (*AsyncFor) ProtoMessage() {} -func (x *ClassDef) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[6] +func (x *AsyncFor) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -590,60 +859,322 @@ func (x *ClassDef) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ClassDef.ProtoReflect.Descriptor instead. -func (*ClassDef) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{6} -} - -func (x *ClassDef) GetName() string { - if x != nil { - return x.Name - } - return "" +// Deprecated: Use AsyncFor.ProtoReflect.Descriptor instead. +func (*AsyncFor) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{7} } -func (x *ClassDef) GetBases() []*Node { +func (x *AsyncFor) GetTarget() *Node { if x != nil { - return x.Bases + return x.Target } return nil } -func (x *ClassDef) GetKeywords() []*Node { +func (x *AsyncFor) GetIter() *Node { if x != nil { - return x.Keywords + return x.Iter } return nil } -func (x *ClassDef) GetBody() []*Node { +func (x *AsyncFor) GetBody() []*Node { if x != nil { return x.Body } return nil } -func (x *ClassDef) GetDecoratorList() []*Node { - if x != nil { - return x.DecoratorList - } - return nil -} - -// The Python ast module does not parse comments. It's not clear if this is the -// best way to support them in the AST -type Comment struct { +type AsyncFunctionDef struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Args *Arguments `protobuf:"bytes,2,opt,name=Args,json=args,proto3" json:"Args,omitempty"` + Body []*Node `protobuf:"bytes,3,rep,name=body,proto3" json:"body,omitempty"` + Returns *Node `protobuf:"bytes,4,opt,name=returns,proto3" json:"returns,omitempty"` +} + +func (x *AsyncFunctionDef) Reset() { + *x = AsyncFunctionDef{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AsyncFunctionDef) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AsyncFunctionDef) ProtoMessage() {} + +func (x *AsyncFunctionDef) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AsyncFunctionDef.ProtoReflect.Descriptor instead. +func (*AsyncFunctionDef) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{8} +} + +func (x *AsyncFunctionDef) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *AsyncFunctionDef) GetArgs() *Arguments { + if x != nil { + return x.Args + } + return nil +} + +func (x *AsyncFunctionDef) GetBody() []*Node { + if x != nil { + return x.Body + } + return nil +} + +func (x *AsyncFunctionDef) GetReturns() *Node { + if x != nil { + return x.Returns + } + return nil +} + +type Assign struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Targets []*Node `protobuf:"bytes,1,rep,name=targets,proto3" json:"targets,omitempty"` + Value *Node `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Comment string `protobuf:"bytes,3,opt,name=Comment,json=comment,proto3" json:"Comment,omitempty"` +} + +func (x *Assign) Reset() { + *x = Assign{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Assign) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Assign) ProtoMessage() {} + +func (x *Assign) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Assign.ProtoReflect.Descriptor instead. +func (*Assign) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{9} +} + +func (x *Assign) GetTargets() []*Node { + if x != nil { + return x.Targets + } + return nil +} + +func (x *Assign) GetValue() *Node { + if x != nil { + return x.Value + } + return nil +} + +func (x *Assign) GetComment() string { + if x != nil { + return x.Comment + } + return "" +} + +type Call struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Func *Node `protobuf:"bytes,1,opt,name=func,proto3" json:"func,omitempty"` + Args []*Node `protobuf:"bytes,2,rep,name=args,proto3" json:"args,omitempty"` + Keywords []*Keyword `protobuf:"bytes,3,rep,name=keywords,proto3" json:"keywords,omitempty"` +} + +func (x *Call) Reset() { + *x = Call{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Call) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Call) ProtoMessage() {} + +func (x *Call) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Call.ProtoReflect.Descriptor instead. +func (*Call) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{10} +} + +func (x *Call) GetFunc() *Node { + if x != nil { + return x.Func + } + return nil +} + +func (x *Call) GetArgs() []*Node { + if x != nil { + return x.Args + } + return nil +} + +func (x *Call) GetKeywords() []*Keyword { + if x != nil { + return x.Keywords + } + return nil +} + +type ClassDef struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Bases []*Node `protobuf:"bytes,2,rep,name=bases,proto3" json:"bases,omitempty"` + Keywords []*Node `protobuf:"bytes,3,rep,name=keywords,proto3" json:"keywords,omitempty"` + Body []*Node `protobuf:"bytes,4,rep,name=body,proto3" json:"body,omitempty"` + DecoratorList []*Node `protobuf:"bytes,5,rep,name=decorator_list,proto3" json:"decorator_list,omitempty"` +} + +func (x *ClassDef) Reset() { + *x = ClassDef{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ClassDef) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ClassDef) ProtoMessage() {} + +func (x *ClassDef) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ClassDef.ProtoReflect.Descriptor instead. +func (*ClassDef) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{11} +} + +func (x *ClassDef) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ClassDef) GetBases() []*Node { + if x != nil { + return x.Bases + } + return nil +} + +func (x *ClassDef) GetKeywords() []*Node { + if x != nil { + return x.Keywords + } + return nil +} + +func (x *ClassDef) GetBody() []*Node { + if x != nil { + return x.Body + } + return nil +} + +func (x *ClassDef) GetDecoratorList() []*Node { + if x != nil { + return x.DecoratorList + } + return nil +} + +// The Python ast module does not parse comments. It's not clear if this is the +// best way to support them in the AST +type Comment struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` } func (x *Comment) Reset() { *x = Comment{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[7] + mi := &file_python_ast_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -656,7 +1187,315 @@ func (x *Comment) String() string { func (*Comment) ProtoMessage() {} func (x *Comment) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[7] + mi := &file_python_ast_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Comment.ProtoReflect.Descriptor instead. +func (*Comment) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{12} +} + +func (x *Comment) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +type Compare struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Left *Node `protobuf:"bytes,1,opt,name=left,proto3" json:"left,omitempty"` + Ops []*Node `protobuf:"bytes,2,rep,name=ops,proto3" json:"ops,omitempty"` + Comparators []*Node `protobuf:"bytes,3,rep,name=comparators,proto3" json:"comparators,omitempty"` +} + +func (x *Compare) Reset() { + *x = Compare{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Compare) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Compare) ProtoMessage() {} + +func (x *Compare) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Compare.ProtoReflect.Descriptor instead. +func (*Compare) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{13} +} + +func (x *Compare) GetLeft() *Node { + if x != nil { + return x.Left + } + return nil +} + +func (x *Compare) GetOps() []*Node { + if x != nil { + return x.Ops + } + return nil +} + +func (x *Compare) GetComparators() []*Node { + if x != nil { + return x.Comparators + } + return nil +} + +type Constant struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Types that are assignable to Value: + // *Constant_Str + // *Constant_Int + // *Constant_None + Value isConstant_Value `protobuf_oneof:"value"` +} + +func (x *Constant) Reset() { + *x = Constant{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Constant) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Constant) ProtoMessage() {} + +func (x *Constant) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[14] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Constant.ProtoReflect.Descriptor instead. +func (*Constant) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{14} +} + +func (m *Constant) GetValue() isConstant_Value { + if m != nil { + return m.Value + } + return nil +} + +func (x *Constant) GetStr() string { + if x, ok := x.GetValue().(*Constant_Str); ok { + return x.Str + } + return "" +} + +func (x *Constant) GetInt() int32 { + if x, ok := x.GetValue().(*Constant_Int); ok { + return x.Int + } + return 0 +} + +func (x *Constant) GetNone() bool { + if x, ok := x.GetValue().(*Constant_None); ok { + return x.None + } + return false +} + +type isConstant_Value interface { + isConstant_Value() +} + +type Constant_Str struct { + Str string `protobuf:"bytes,1,opt,name=str,json=string,proto3,oneof"` +} + +type Constant_Int struct { + Int int32 `protobuf:"varint,2,opt,name=int,proto3,oneof"` +} + +type Constant_None struct { + None bool `protobuf:"varint,3,opt,name=none,proto3,oneof"` +} + +func (*Constant_Str) isConstant_Value() {} + +func (*Constant_Int) isConstant_Value() {} + +func (*Constant_None) isConstant_Value() {} + +type Dict struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Keys []*Node `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` + Values []*Node `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` +} + +func (x *Dict) Reset() { + *x = Dict{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Dict) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Dict) ProtoMessage() {} + +func (x *Dict) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[15] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Dict.ProtoReflect.Descriptor instead. +func (*Dict) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{15} +} + +func (x *Dict) GetKeys() []*Node { + if x != nil { + return x.Keys + } + return nil +} + +func (x *Dict) GetValues() []*Node { + if x != nil { + return x.Values + } + return nil +} + +type Expr struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Expr) Reset() { + *x = Expr{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Expr) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Expr) ProtoMessage() {} + +func (x *Expr) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[16] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Expr.ProtoReflect.Descriptor instead. +func (*Expr) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{16} +} + +func (x *Expr) GetValue() *Node { + if x != nil { + return x.Value + } + return nil +} + +type For struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Target *Node `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` + Iter *Node `protobuf:"bytes,2,opt,name=iter,proto3" json:"iter,omitempty"` + Body []*Node `protobuf:"bytes,3,rep,name=body,proto3" json:"body,omitempty"` +} + +func (x *For) Reset() { + *x = For{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *For) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*For) ProtoMessage() {} + +func (x *For) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -664,46 +1503,63 @@ func (x *Comment) ProtoReflect() protoreflect.Message { } return ms } - return mi.MessageOf(x) + return mi.MessageOf(x) +} + +// Deprecated: Use For.ProtoReflect.Descriptor instead. +func (*For) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{17} +} + +func (x *For) GetTarget() *Node { + if x != nil { + return x.Target + } + return nil } -// Deprecated: Use Comment.ProtoReflect.Descriptor instead. -func (*Comment) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{7} +func (x *For) GetIter() *Node { + if x != nil { + return x.Iter + } + return nil } -func (x *Comment) GetText() string { +func (x *For) GetBody() []*Node { if x != nil { - return x.Text + return x.Body } - return "" + return nil } -type Constant struct { +type FunctionDef struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Args *Arguments `protobuf:"bytes,2,opt,name=Args,json=args,proto3" json:"Args,omitempty"` + Body []*Node `protobuf:"bytes,3,rep,name=body,proto3" json:"body,omitempty"` + Returns *Node `protobuf:"bytes,4,opt,name=returns,proto3" json:"returns,omitempty"` } -func (x *Constant) Reset() { - *x = Constant{} +func (x *FunctionDef) Reset() { + *x = FunctionDef{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[8] + mi := &file_python_ast_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Constant) String() string { +func (x *FunctionDef) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Constant) ProtoMessage() {} +func (*FunctionDef) ProtoMessage() {} -func (x *Constant) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[8] +func (x *FunctionDef) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -714,43 +1570,66 @@ func (x *Constant) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Constant.ProtoReflect.Descriptor instead. -func (*Constant) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{8} +// Deprecated: Use FunctionDef.ProtoReflect.Descriptor instead. +func (*FunctionDef) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{18} } -func (x *Constant) GetValue() string { +func (x *FunctionDef) GetName() string { if x != nil { - return x.Value + return x.Name } return "" } -type Expr struct { +func (x *FunctionDef) GetArgs() *Arguments { + if x != nil { + return x.Args + } + return nil +} + +func (x *FunctionDef) GetBody() []*Node { + if x != nil { + return x.Body + } + return nil +} + +func (x *FunctionDef) GetReturns() *Node { + if x != nil { + return x.Returns + } + return nil +} + +type If struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + Test *Node `protobuf:"bytes,1,opt,name=test,proto3" json:"test,omitempty"` + Body []*Node `protobuf:"bytes,2,rep,name=body,proto3" json:"body,omitempty"` + OrElse []*Node `protobuf:"bytes,3,rep,name=or_else,json=orelse,proto3" json:"or_else,omitempty"` } -func (x *Expr) Reset() { - *x = Expr{} +func (x *If) Reset() { + *x = If{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[9] + mi := &file_python_ast_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Expr) String() string { +func (x *If) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Expr) ProtoMessage() {} +func (*If) ProtoMessage() {} -func (x *Expr) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[9] +func (x *If) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -761,14 +1640,28 @@ func (x *Expr) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Expr.ProtoReflect.Descriptor instead. -func (*Expr) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{9} +// Deprecated: Use If.ProtoReflect.Descriptor instead. +func (*If) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{19} } -func (x *Expr) GetValue() *Node { +func (x *If) GetTest() *Node { if x != nil { - return x.Value + return x.Test + } + return nil +} + +func (x *If) GetBody() []*Node { + if x != nil { + return x.Body + } + return nil +} + +func (x *If) GetOrElse() []*Node { + if x != nil { + return x.OrElse } return nil } @@ -784,7 +1677,7 @@ type Import struct { func (x *Import) Reset() { *x = Import{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[10] + mi := &file_python_ast_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -797,7 +1690,7 @@ func (x *Import) String() string { func (*Import) ProtoMessage() {} func (x *Import) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[10] + mi := &file_python_ast_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -810,7 +1703,7 @@ func (x *Import) ProtoReflect() protoreflect.Message { // Deprecated: Use Import.ProtoReflect.Descriptor instead. func (*Import) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{10} + return file_python_ast_proto_rawDescGZIP(), []int{20} } func (x *Import) GetNames() []*Node { @@ -833,7 +1726,7 @@ type ImportFrom struct { func (x *ImportFrom) Reset() { *x = ImportFrom{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[11] + mi := &file_python_ast_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -846,7 +1739,7 @@ func (x *ImportFrom) String() string { func (*ImportFrom) ProtoMessage() {} func (x *ImportFrom) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[11] + mi := &file_python_ast_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -859,7 +1752,7 @@ func (x *ImportFrom) ProtoReflect() protoreflect.Message { // Deprecated: Use ImportFrom.ProtoReflect.Descriptor instead. func (*ImportFrom) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{11} + return file_python_ast_proto_rawDescGZIP(), []int{21} } func (x *ImportFrom) GetModule() string { @@ -883,6 +1776,158 @@ func (x *ImportFrom) GetLevel() int32 { return 0 } +// Imports are always put at the top of the file, just after any module +// comments and docstrings, and before module globals and constants. +// +// Imports should be grouped in the following order: +// +// Standard library imports. +// Related third party imports. +// Local application/library specific imports. +// +// You should put a blank line between each group of imports. +// +// https://www.python.org/dev/peps/pep-0008/#imports +type ImportGroup struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Imports []*Node `protobuf:"bytes,1,rep,name=imports,proto3" json:"imports,omitempty"` +} + +func (x *ImportGroup) Reset() { + *x = ImportGroup{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ImportGroup) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ImportGroup) ProtoMessage() {} + +func (x *ImportGroup) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[22] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ImportGroup.ProtoReflect.Descriptor instead. +func (*ImportGroup) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{22} +} + +func (x *ImportGroup) GetImports() []*Node { + if x != nil { + return x.Imports + } + return nil +} + +type Is struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Is) Reset() { + *x = Is{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Is) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Is) ProtoMessage() {} + +func (x *Is) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[23] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Is.ProtoReflect.Descriptor instead. +func (*Is) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{23} +} + +type Keyword struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Arg string `protobuf:"bytes,1,opt,name=arg,proto3" json:"arg,omitempty"` + Value *Node `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Keyword) Reset() { + *x = Keyword{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[24] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Keyword) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Keyword) ProtoMessage() {} + +func (x *Keyword) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[24] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Keyword.ProtoReflect.Descriptor instead. +func (*Keyword) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{24} +} + +func (x *Keyword) GetArg() string { + if x != nil { + return x.Arg + } + return "" +} + +func (x *Keyword) GetValue() *Node { + if x != nil { + return x.Value + } + return nil +} + type Module struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -894,20 +1939,112 @@ type Module struct { func (x *Module) Reset() { *x = Module{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[12] + mi := &file_python_ast_proto_msgTypes[25] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Module) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Module) ProtoMessage() {} + +func (x *Module) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[25] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Module.ProtoReflect.Descriptor instead. +func (*Module) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{25} +} + +func (x *Module) GetBody() []*Node { + if x != nil { + return x.Body + } + return nil +} + +type Name struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *Name) Reset() { + *x = Name{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Name) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Name) ProtoMessage() {} + +func (x *Name) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[26] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Name.ProtoReflect.Descriptor instead. +func (*Name) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{26} +} + +func (x *Name) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type Pass struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Pass) Reset() { + *x = Pass{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Module) String() string { +func (x *Pass) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Module) ProtoMessage() {} +func (*Pass) ProtoMessage() {} -func (x *Module) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[12] +func (x *Pass) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -918,43 +2055,36 @@ func (x *Module) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Module.ProtoReflect.Descriptor instead. -func (*Module) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{12} -} - -func (x *Module) GetBody() []*Node { - if x != nil { - return x.Body - } - return nil +// Deprecated: Use Pass.ProtoReflect.Descriptor instead. +func (*Pass) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{27} } -type Name struct { +type Return struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` } -func (x *Name) Reset() { - *x = Name{} +func (x *Return) Reset() { + *x = Return{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[13] + mi := &file_python_ast_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *Name) String() string { +func (x *Return) String() string { return protoimpl.X.MessageStringOf(x) } -func (*Name) ProtoMessage() {} +func (*Return) ProtoMessage() {} -func (x *Name) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[13] +func (x *Return) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[28] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -965,16 +2095,16 @@ func (x *Name) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Name.ProtoReflect.Descriptor instead. -func (*Name) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{13} +// Deprecated: Use Return.ProtoReflect.Descriptor instead. +func (*Return) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{28} } -func (x *Name) GetId() string { +func (x *Return) GetValue() *Node { if x != nil { - return x.Id + return x.Value } - return "" + return nil } type Subscript struct { @@ -989,7 +2119,7 @@ type Subscript struct { func (x *Subscript) Reset() { *x = Subscript{} if protoimpl.UnsafeEnabled { - mi := &file_python_ast_proto_msgTypes[14] + mi := &file_python_ast_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1002,7 +2132,7 @@ func (x *Subscript) String() string { func (*Subscript) ProtoMessage() {} func (x *Subscript) ProtoReflect() protoreflect.Message { - mi := &file_python_ast_proto_msgTypes[14] + mi := &file_python_ast_proto_msgTypes[29] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1015,7 +2145,7 @@ func (x *Subscript) ProtoReflect() protoreflect.Message { // Deprecated: Use Subscript.ProtoReflect.Descriptor instead. func (*Subscript) Descriptor() ([]byte, []int) { - return file_python_ast_proto_rawDescGZIP(), []int{14} + return file_python_ast_proto_rawDescGZIP(), []int{29} } func (x *Subscript) GetValue() *Name { @@ -1032,11 +2162,58 @@ func (x *Subscript) GetSlice() *Node { return nil } +type Yield struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value *Node `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Yield) Reset() { + *x = Yield{} + if protoimpl.UnsafeEnabled { + mi := &file_python_ast_proto_msgTypes[30] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Yield) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Yield) ProtoMessage() {} + +func (x *Yield) ProtoReflect() protoreflect.Message { + mi := &file_python_ast_proto_msgTypes[30] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Yield.ProtoReflect.Descriptor instead. +func (*Yield) Descriptor() ([]byte, []int) { + return file_python_ast_proto_rawDescGZIP(), []int{30} +} + +func (x *Yield) GetValue() *Node { + if x != nil { + return x.Value + } + return nil +} + var File_python_ast_proto protoreflect.FileDescriptor var file_python_ast_proto_rawDesc = []byte{ 0x0a, 0x10, 0x70, 0x79, 0x74, 0x68, 0x6f, 0x6e, 0x2f, 0x61, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x12, 0x03, 0x61, 0x73, 0x74, 0x22, 0xd4, 0x04, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, + 0x74, 0x6f, 0x12, 0x03, 0x61, 0x73, 0x74, 0x22, 0xde, 0x09, 0x0a, 0x04, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x2c, 0x0a, 0x09, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, 0x64, 0x65, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x66, 0x48, 0x00, 0x52, 0x08, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x66, 0x12, 0x25, @@ -1073,71 +2250,194 @@ var file_python_ast_proto_rawDesc = []byte{ 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x70, 0x72, 0x48, 0x00, 0x52, 0x04, 0x45, 0x78, 0x70, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x63, 0x61, 0x6c, 0x6c, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x48, 0x00, - 0x52, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x42, 0x06, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x1b, - 0x0a, 0x05, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x40, 0x0a, 0x09, 0x41, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x61, - 0x6d, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x74, 0x74, - 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x74, 0x74, 0x72, 0x22, 0x8b, 0x01, - 0x0a, 0x09, 0x41, 0x6e, 0x6e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x12, 0x21, 0x0a, 0x06, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, - 0x74, 0x2e, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x29, - 0x0a, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x61, - 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x69, 0x6d, - 0x70, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x69, 0x6d, 0x70, 0x6c, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x68, 0x0a, 0x06, 0x41, - 0x73, 0x73, 0x69, 0x67, 0x6e, 0x12, 0x23, 0x0a, 0x07, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x61, 0x6d, - 0x65, 0x52, 0x07, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, - 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, - 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, - 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x25, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x1d, 0x0a, - 0x04, 0x66, 0x75, 0x6e, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, - 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x66, 0x75, 0x6e, 0x63, 0x22, 0xb8, 0x01, 0x0a, - 0x08, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x66, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1f, 0x0a, - 0x05, 0x62, 0x61, 0x73, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, - 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x62, 0x61, 0x73, 0x65, 0x73, 0x12, 0x25, - 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x6b, 0x65, 0x79, - 0x77, 0x6f, 0x72, 0x64, 0x73, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x12, 0x31, 0x0a, 0x0e, 0x64, 0x65, 0x63, 0x6f, 0x72, 0x61, 0x74, 0x6f, - 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, - 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0e, 0x64, 0x65, 0x63, 0x6f, 0x72, 0x61, 0x74, - 0x6f, 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x1d, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, - 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x20, 0x0a, 0x08, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, - 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x27, 0x0a, 0x04, 0x45, 0x78, 0x70, 0x72, - 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x22, 0x29, 0x0a, 0x06, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x6e, - 0x61, 0x6d, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, - 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x22, 0x5b, 0x0a, 0x0a, - 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x46, 0x72, 0x6f, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x6f, - 0x64, 0x75, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x6e, 0x61, - 0x6d, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x22, 0x27, 0x0a, 0x06, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, - 0x64, 0x79, 0x22, 0x16, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x4d, 0x0a, 0x09, 0x53, 0x75, - 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x61, 0x6d, - 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x6c, 0x69, 0x63, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, - 0x64, 0x65, 0x52, 0x05, 0x73, 0x6c, 0x69, 0x63, 0x65, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x79, 0x6c, 0x65, 0x63, 0x6f, 0x6e, 0x72, - 0x6f, 0x79, 0x2f, 0x73, 0x71, 0x6c, 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x2f, 0x70, 0x79, 0x74, 0x68, 0x6f, 0x6e, 0x2f, 0x61, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x52, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x35, 0x0a, 0x0c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x64, 0x65, 0x66, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, + 0x73, 0x74, 0x2e, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x66, 0x48, 0x00, + 0x52, 0x0b, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x66, 0x12, 0x1c, 0x0a, + 0x03, 0x61, 0x72, 0x67, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x61, 0x73, 0x74, + 0x2e, 0x41, 0x72, 0x67, 0x48, 0x00, 0x52, 0x03, 0x41, 0x72, 0x67, 0x12, 0x2e, 0x0a, 0x09, 0x61, + 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, + 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, + 0x52, 0x09, 0x41, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x45, 0x0a, 0x12, 0x61, + 0x73, 0x79, 0x6e, 0x63, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x64, 0x65, + 0x66, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x73, + 0x79, 0x6e, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x66, 0x48, 0x00, + 0x52, 0x10, 0x41, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, + 0x65, 0x66, 0x12, 0x1f, 0x0a, 0x04, 0x70, 0x61, 0x73, 0x73, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x48, 0x00, 0x52, 0x04, 0x50, + 0x61, 0x73, 0x73, 0x12, 0x1f, 0x0a, 0x04, 0x64, 0x69, 0x63, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x44, 0x69, 0x63, 0x74, 0x48, 0x00, 0x52, 0x04, + 0x44, 0x69, 0x63, 0x74, 0x12, 0x19, 0x0a, 0x02, 0x69, 0x66, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x07, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x49, 0x66, 0x48, 0x00, 0x52, 0x02, 0x49, 0x66, 0x12, + 0x28, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0c, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x48, 0x00, + 0x52, 0x07, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x12, 0x25, 0x0a, 0x06, 0x72, 0x65, 0x74, + 0x75, 0x72, 0x6e, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x61, 0x73, 0x74, 0x2e, + 0x52, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x48, 0x00, 0x52, 0x06, 0x52, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x12, 0x19, 0x0a, 0x02, 0x69, 0x73, 0x18, 0x18, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x61, + 0x73, 0x74, 0x2e, 0x49, 0x73, 0x48, 0x00, 0x52, 0x02, 0x49, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x6b, + 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x19, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, + 0x73, 0x74, 0x2e, 0x4b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x48, 0x00, 0x52, 0x07, 0x4b, 0x65, + 0x79, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x22, 0x0a, 0x05, 0x79, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1a, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x59, 0x69, 0x65, 0x6c, 0x64, + 0x48, 0x00, 0x52, 0x05, 0x59, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1c, 0x0a, 0x03, 0x66, 0x6f, 0x72, + 0x18, 0x1b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x46, 0x6f, 0x72, + 0x48, 0x00, 0x52, 0x03, 0x46, 0x6f, 0x72, 0x12, 0x22, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x69, 0x74, + 0x18, 0x1c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x77, 0x61, + 0x69, 0x74, 0x48, 0x00, 0x52, 0x05, 0x41, 0x77, 0x61, 0x69, 0x74, 0x12, 0x2c, 0x0a, 0x09, 0x61, + 0x73, 0x79, 0x6e, 0x63, 0x5f, 0x66, 0x6f, 0x72, 0x18, 0x1d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, + 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x6f, 0x72, 0x48, 0x00, 0x52, + 0x08, 0x41, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x6f, 0x72, 0x12, 0x35, 0x0a, 0x0c, 0x69, 0x6d, 0x70, + 0x6f, 0x72, 0x74, 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x10, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x47, 0x72, 0x6f, 0x75, + 0x70, 0x48, 0x00, 0x52, 0x0b, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, + 0x42, 0x06, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x1b, 0x0a, 0x05, 0x41, 0x6c, 0x69, 0x61, + 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x28, 0x0a, 0x05, 0x41, 0x77, 0x61, 0x69, 0x74, 0x12, 0x1f, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, + 0x40, 0x0a, 0x09, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, + 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x61, 0x74, 0x74, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x74, 0x74, + 0x72, 0x22, 0x8b, 0x01, 0x0a, 0x09, 0x41, 0x6e, 0x6e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x12, + 0x21, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x12, 0x29, 0x0a, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, + 0x06, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, + 0x42, 0x0a, 0x03, 0x41, 0x72, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x72, 0x67, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x61, 0x72, 0x67, 0x12, 0x29, 0x0a, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, + 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, + 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0x55, 0x0a, 0x09, 0x41, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x12, 0x1c, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, + 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x72, 0x67, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x2a, + 0x0a, 0x0c, 0x6b, 0x77, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x72, 0x67, 0x52, 0x0a, + 0x6b, 0x77, 0x6f, 0x6e, 0x6c, 0x79, 0x61, 0x72, 0x67, 0x73, 0x22, 0x6b, 0x0a, 0x08, 0x41, 0x73, + 0x79, 0x6e, 0x63, 0x46, 0x6f, 0x72, 0x12, 0x21, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1d, 0x0a, 0x04, 0x69, 0x74, 0x65, + 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x8e, 0x01, 0x0a, 0x10, 0x41, 0x73, 0x79, 0x6e, + 0x63, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x66, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x22, 0x0a, 0x04, 0x41, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, + 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x04, + 0x61, 0x72, 0x67, 0x73, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, + 0x6f, 0x64, 0x79, 0x12, 0x23, 0x0a, 0x07, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, + 0x07, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x22, 0x68, 0x0a, 0x06, 0x41, 0x73, 0x73, 0x69, + 0x67, 0x6e, 0x12, 0x23, 0x0a, 0x07, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x07, + 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, + 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x22, 0x6e, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x1d, 0x0a, 0x04, 0x66, 0x75, + 0x6e, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, + 0x6f, 0x64, 0x65, 0x52, 0x04, 0x66, 0x75, 0x6e, 0x63, 0x12, 0x1d, 0x0a, 0x04, 0x61, 0x72, 0x67, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x28, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, + 0x6f, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, 0x73, 0x74, + 0x2e, 0x4b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, + 0x64, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x08, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x44, 0x65, 0x66, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x62, 0x61, 0x73, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x62, + 0x61, 0x73, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x73, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x73, 0x12, 0x1d, 0x0a, 0x04, 0x62, + 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x31, 0x0a, 0x0e, 0x64, 0x65, + 0x63, 0x6f, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0e, 0x64, + 0x65, 0x63, 0x6f, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x1d, 0x0a, + 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x72, 0x0a, 0x07, + 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x12, 0x1d, 0x0a, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, + 0x52, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x12, 0x1b, 0x0a, 0x03, 0x6f, 0x70, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x03, + 0x6f, 0x70, 0x73, 0x12, 0x2b, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x61, 0x74, 0x6f, + 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, + 0x6f, 0x64, 0x65, 0x52, 0x0b, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x73, + 0x22, 0x54, 0x0a, 0x08, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x12, 0x15, 0x0a, 0x03, + 0x73, 0x74, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x06, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x12, 0x12, 0x0a, 0x03, 0x69, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x48, 0x00, 0x52, 0x03, 0x69, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x42, 0x07, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x48, 0x0a, 0x04, 0x44, 0x69, 0x63, 0x74, 0x12, 0x1d, + 0x0a, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, + 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x12, 0x21, 0x0a, + 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, + 0x22, 0x27, 0x0a, 0x04, 0x45, 0x78, 0x70, 0x72, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x66, 0x0a, 0x03, 0x46, 0x6f, 0x72, + 0x12, 0x21, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x06, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x12, 0x1d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x69, 0x74, + 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x22, 0x89, 0x01, 0x0a, 0x0b, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, + 0x66, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x41, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x41, 0x72, 0x67, 0x75, 0x6d, 0x65, + 0x6e, 0x74, 0x73, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x23, 0x0a, 0x07, 0x72, 0x65, 0x74, 0x75, + 0x72, 0x6e, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x07, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x22, 0x66, 0x0a, + 0x02, 0x49, 0x66, 0x12, 0x1d, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x74, 0x65, + 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x12, 0x22, 0x0a, 0x07, 0x6f, 0x72, 0x5f, 0x65, 0x6c, 0x73, 0x65, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x06, 0x6f, + 0x72, 0x65, 0x6c, 0x73, 0x65, 0x22, 0x29, 0x0a, 0x06, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x12, + 0x1f, 0x0a, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, + 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, + 0x22, 0x5b, 0x0a, 0x0a, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x46, 0x72, 0x6f, 0x6d, 0x12, 0x16, + 0x0a, 0x06, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, + 0x52, 0x05, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x22, 0x32, 0x0a, + 0x0b, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x23, 0x0a, 0x07, + 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x07, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, + 0x73, 0x22, 0x04, 0x0a, 0x02, 0x49, 0x73, 0x22, 0x3c, 0x0a, 0x07, 0x4b, 0x65, 0x79, 0x77, 0x6f, + 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x72, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x61, 0x72, 0x67, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x27, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, + 0x1d, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x16, + 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x06, 0x0a, 0x04, 0x50, 0x61, 0x73, 0x73, 0x22, 0x29, + 0x0a, 0x06, 0x52, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, + 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4d, 0x0a, 0x09, 0x53, 0x75, 0x62, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x61, 0x6d, 0x65, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x6c, 0x69, 0x63, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x05, 0x73, 0x6c, 0x69, 0x63, 0x65, 0x22, 0x28, 0x0a, 0x05, 0x59, 0x69, 0x65, 0x6c, + 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x09, 0x2e, 0x61, 0x73, 0x74, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x6b, 0x79, 0x6c, 0x65, 0x63, 0x6f, 0x6e, 0x72, 0x6f, 0x79, 0x2f, 0x73, 0x71, 0x6c, 0x63, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x79, 0x74, 0x68, 0x6f, 0x6e, + 0x2f, 0x61, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1152,60 +2452,122 @@ func file_python_ast_proto_rawDescGZIP() []byte { return file_python_ast_proto_rawDescData } -var file_python_ast_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_python_ast_proto_msgTypes = make([]protoimpl.MessageInfo, 31) var file_python_ast_proto_goTypes = []interface{}{ - (*Node)(nil), // 0: ast.Node - (*Alias)(nil), // 1: ast.Alias - (*Attribute)(nil), // 2: ast.Attribute - (*AnnAssign)(nil), // 3: ast.AnnAssign - (*Assign)(nil), // 4: ast.Assign - (*Call)(nil), // 5: ast.Call - (*ClassDef)(nil), // 6: ast.ClassDef - (*Comment)(nil), // 7: ast.Comment - (*Constant)(nil), // 8: ast.Constant - (*Expr)(nil), // 9: ast.Expr - (*Import)(nil), // 10: ast.Import - (*ImportFrom)(nil), // 11: ast.ImportFrom - (*Module)(nil), // 12: ast.Module - (*Name)(nil), // 13: ast.Name - (*Subscript)(nil), // 14: ast.Subscript + (*Node)(nil), // 0: ast.Node + (*Alias)(nil), // 1: ast.Alias + (*Await)(nil), // 2: ast.Await + (*Attribute)(nil), // 3: ast.Attribute + (*AnnAssign)(nil), // 4: ast.AnnAssign + (*Arg)(nil), // 5: ast.Arg + (*Arguments)(nil), // 6: ast.Arguments + (*AsyncFor)(nil), // 7: ast.AsyncFor + (*AsyncFunctionDef)(nil), // 8: ast.AsyncFunctionDef + (*Assign)(nil), // 9: ast.Assign + (*Call)(nil), // 10: ast.Call + (*ClassDef)(nil), // 11: ast.ClassDef + (*Comment)(nil), // 12: ast.Comment + (*Compare)(nil), // 13: ast.Compare + (*Constant)(nil), // 14: ast.Constant + (*Dict)(nil), // 15: ast.Dict + (*Expr)(nil), // 16: ast.Expr + (*For)(nil), // 17: ast.For + (*FunctionDef)(nil), // 18: ast.FunctionDef + (*If)(nil), // 19: ast.If + (*Import)(nil), // 20: ast.Import + (*ImportFrom)(nil), // 21: ast.ImportFrom + (*ImportGroup)(nil), // 22: ast.ImportGroup + (*Is)(nil), // 23: ast.Is + (*Keyword)(nil), // 24: ast.Keyword + (*Module)(nil), // 25: ast.Module + (*Name)(nil), // 26: ast.Name + (*Pass)(nil), // 27: ast.Pass + (*Return)(nil), // 28: ast.Return + (*Subscript)(nil), // 29: ast.Subscript + (*Yield)(nil), // 30: ast.Yield } var file_python_ast_proto_depIdxs = []int32{ - 6, // 0: ast.Node.class_def:type_name -> ast.ClassDef - 10, // 1: ast.Node.import:type_name -> ast.Import - 11, // 2: ast.Node.import_from:type_name -> ast.ImportFrom - 12, // 3: ast.Node.module:type_name -> ast.Module + 11, // 0: ast.Node.class_def:type_name -> ast.ClassDef + 20, // 1: ast.Node.import:type_name -> ast.Import + 21, // 2: ast.Node.import_from:type_name -> ast.ImportFrom + 25, // 3: ast.Node.module:type_name -> ast.Module 1, // 4: ast.Node.alias:type_name -> ast.Alias - 3, // 5: ast.Node.ann_assign:type_name -> ast.AnnAssign - 13, // 6: ast.Node.name:type_name -> ast.Name - 14, // 7: ast.Node.subscript:type_name -> ast.Subscript - 2, // 8: ast.Node.attribute:type_name -> ast.Attribute - 8, // 9: ast.Node.constant:type_name -> ast.Constant - 4, // 10: ast.Node.assign:type_name -> ast.Assign - 7, // 11: ast.Node.comment:type_name -> ast.Comment - 9, // 12: ast.Node.expr:type_name -> ast.Expr - 5, // 13: ast.Node.call:type_name -> ast.Call - 13, // 14: ast.Attribute.value:type_name -> ast.Name - 13, // 15: ast.AnnAssign.target:type_name -> ast.Name - 0, // 16: ast.AnnAssign.annotation:type_name -> ast.Node - 13, // 17: ast.Assign.targets:type_name -> ast.Name - 0, // 18: ast.Assign.value:type_name -> ast.Node - 0, // 19: ast.Call.func:type_name -> ast.Node - 0, // 20: ast.ClassDef.bases:type_name -> ast.Node - 0, // 21: ast.ClassDef.keywords:type_name -> ast.Node - 0, // 22: ast.ClassDef.body:type_name -> ast.Node - 0, // 23: ast.ClassDef.decorator_list:type_name -> ast.Node - 0, // 24: ast.Expr.value:type_name -> ast.Node - 0, // 25: ast.Import.names:type_name -> ast.Node - 0, // 26: ast.ImportFrom.names:type_name -> ast.Node - 0, // 27: ast.Module.body:type_name -> ast.Node - 13, // 28: ast.Subscript.value:type_name -> ast.Name - 0, // 29: ast.Subscript.slice:type_name -> ast.Node - 30, // [30:30] is the sub-list for method output_type - 30, // [30:30] is the sub-list for method input_type - 30, // [30:30] is the sub-list for extension type_name - 30, // [30:30] is the sub-list for extension extendee - 0, // [0:30] is the sub-list for field type_name + 4, // 5: ast.Node.ann_assign:type_name -> ast.AnnAssign + 26, // 6: ast.Node.name:type_name -> ast.Name + 29, // 7: ast.Node.subscript:type_name -> ast.Subscript + 3, // 8: ast.Node.attribute:type_name -> ast.Attribute + 14, // 9: ast.Node.constant:type_name -> ast.Constant + 9, // 10: ast.Node.assign:type_name -> ast.Assign + 12, // 11: ast.Node.comment:type_name -> ast.Comment + 16, // 12: ast.Node.expr:type_name -> ast.Expr + 10, // 13: ast.Node.call:type_name -> ast.Call + 18, // 14: ast.Node.function_def:type_name -> ast.FunctionDef + 5, // 15: ast.Node.arg:type_name -> ast.Arg + 6, // 16: ast.Node.arguments:type_name -> ast.Arguments + 8, // 17: ast.Node.async_function_def:type_name -> ast.AsyncFunctionDef + 27, // 18: ast.Node.pass:type_name -> ast.Pass + 15, // 19: ast.Node.dict:type_name -> ast.Dict + 19, // 20: ast.Node.if:type_name -> ast.If + 13, // 21: ast.Node.compare:type_name -> ast.Compare + 28, // 22: ast.Node.return:type_name -> ast.Return + 23, // 23: ast.Node.is:type_name -> ast.Is + 24, // 24: ast.Node.keyword:type_name -> ast.Keyword + 30, // 25: ast.Node.yield:type_name -> ast.Yield + 17, // 26: ast.Node.for:type_name -> ast.For + 2, // 27: ast.Node.await:type_name -> ast.Await + 7, // 28: ast.Node.async_for:type_name -> ast.AsyncFor + 22, // 29: ast.Node.import_group:type_name -> ast.ImportGroup + 0, // 30: ast.Await.value:type_name -> ast.Node + 0, // 31: ast.Attribute.value:type_name -> ast.Node + 26, // 32: ast.AnnAssign.target:type_name -> ast.Name + 0, // 33: ast.AnnAssign.annotation:type_name -> ast.Node + 0, // 34: ast.Arg.annotation:type_name -> ast.Node + 5, // 35: ast.Arguments.args:type_name -> ast.Arg + 5, // 36: ast.Arguments.kw_only_args:type_name -> ast.Arg + 0, // 37: ast.AsyncFor.target:type_name -> ast.Node + 0, // 38: ast.AsyncFor.iter:type_name -> ast.Node + 0, // 39: ast.AsyncFor.body:type_name -> ast.Node + 6, // 40: ast.AsyncFunctionDef.Args:type_name -> ast.Arguments + 0, // 41: ast.AsyncFunctionDef.body:type_name -> ast.Node + 0, // 42: ast.AsyncFunctionDef.returns:type_name -> ast.Node + 0, // 43: ast.Assign.targets:type_name -> ast.Node + 0, // 44: ast.Assign.value:type_name -> ast.Node + 0, // 45: ast.Call.func:type_name -> ast.Node + 0, // 46: ast.Call.args:type_name -> ast.Node + 24, // 47: ast.Call.keywords:type_name -> ast.Keyword + 0, // 48: ast.ClassDef.bases:type_name -> ast.Node + 0, // 49: ast.ClassDef.keywords:type_name -> ast.Node + 0, // 50: ast.ClassDef.body:type_name -> ast.Node + 0, // 51: ast.ClassDef.decorator_list:type_name -> ast.Node + 0, // 52: ast.Compare.left:type_name -> ast.Node + 0, // 53: ast.Compare.ops:type_name -> ast.Node + 0, // 54: ast.Compare.comparators:type_name -> ast.Node + 0, // 55: ast.Dict.keys:type_name -> ast.Node + 0, // 56: ast.Dict.values:type_name -> ast.Node + 0, // 57: ast.Expr.value:type_name -> ast.Node + 0, // 58: ast.For.target:type_name -> ast.Node + 0, // 59: ast.For.iter:type_name -> ast.Node + 0, // 60: ast.For.body:type_name -> ast.Node + 6, // 61: ast.FunctionDef.Args:type_name -> ast.Arguments + 0, // 62: ast.FunctionDef.body:type_name -> ast.Node + 0, // 63: ast.FunctionDef.returns:type_name -> ast.Node + 0, // 64: ast.If.test:type_name -> ast.Node + 0, // 65: ast.If.body:type_name -> ast.Node + 0, // 66: ast.If.or_else:type_name -> ast.Node + 0, // 67: ast.Import.names:type_name -> ast.Node + 0, // 68: ast.ImportFrom.names:type_name -> ast.Node + 0, // 69: ast.ImportGroup.imports:type_name -> ast.Node + 0, // 70: ast.Keyword.value:type_name -> ast.Node + 0, // 71: ast.Module.body:type_name -> ast.Node + 0, // 72: ast.Return.value:type_name -> ast.Node + 26, // 73: ast.Subscript.value:type_name -> ast.Name + 0, // 74: ast.Subscript.slice:type_name -> ast.Node + 0, // 75: ast.Yield.value:type_name -> ast.Node + 76, // [76:76] is the sub-list for method output_type + 76, // [76:76] is the sub-list for method input_type + 76, // [76:76] is the sub-list for extension type_name + 76, // [76:76] is the sub-list for extension extendee + 0, // [0:76] is the sub-list for field type_name } func init() { file_python_ast_proto_init() } @@ -1239,7 +2601,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Attribute); i { + switch v := v.(*Await); i { case 0: return &v.state case 1: @@ -1251,7 +2613,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AnnAssign); i { + switch v := v.(*Attribute); i { case 0: return &v.state case 1: @@ -1263,7 +2625,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Assign); i { + switch v := v.(*AnnAssign); i { case 0: return &v.state case 1: @@ -1275,7 +2637,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Call); i { + switch v := v.(*Arg); i { case 0: return &v.state case 1: @@ -1287,7 +2649,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ClassDef); i { + switch v := v.(*Arguments); i { case 0: return &v.state case 1: @@ -1299,7 +2661,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Comment); i { + switch v := v.(*AsyncFor); i { case 0: return &v.state case 1: @@ -1311,7 +2673,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Constant); i { + switch v := v.(*AsyncFunctionDef); i { case 0: return &v.state case 1: @@ -1323,7 +2685,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Expr); i { + switch v := v.(*Assign); i { case 0: return &v.state case 1: @@ -1335,7 +2697,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Import); i { + switch v := v.(*Call); i { case 0: return &v.state case 1: @@ -1347,7 +2709,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ImportFrom); i { + switch v := v.(*ClassDef); i { case 0: return &v.state case 1: @@ -1359,7 +2721,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Module); i { + switch v := v.(*Comment); i { case 0: return &v.state case 1: @@ -1371,7 +2733,7 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Name); i { + switch v := v.(*Compare); i { case 0: return &v.state case 1: @@ -1383,6 +2745,186 @@ func file_python_ast_proto_init() { } } file_python_ast_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Constant); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Dict); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Expr); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*For); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FunctionDef); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*If); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Import); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ImportFrom); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ImportGroup); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Is); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Keyword); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Module); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Name); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Pass); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Return); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_python_ast_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Subscript); i { case 0: return &v.state @@ -1394,6 +2936,18 @@ func file_python_ast_proto_init() { return nil } } + file_python_ast_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Yield); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } file_python_ast_proto_msgTypes[0].OneofWrappers = []interface{}{ (*Node_ClassDef)(nil), @@ -1410,6 +2964,27 @@ func file_python_ast_proto_init() { (*Node_Comment)(nil), (*Node_Expr)(nil), (*Node_Call)(nil), + (*Node_FunctionDef)(nil), + (*Node_Arg)(nil), + (*Node_Arguments)(nil), + (*Node_AsyncFunctionDef)(nil), + (*Node_Pass)(nil), + (*Node_Dict)(nil), + (*Node_If)(nil), + (*Node_Compare)(nil), + (*Node_Return)(nil), + (*Node_Is)(nil), + (*Node_Keyword)(nil), + (*Node_Yield)(nil), + (*Node_For)(nil), + (*Node_Await)(nil), + (*Node_AsyncFor)(nil), + (*Node_ImportGroup)(nil), + } + file_python_ast_proto_msgTypes[14].OneofWrappers = []interface{}{ + (*Constant_Str)(nil), + (*Constant_Int)(nil), + (*Constant_None)(nil), } type x struct{} out := protoimpl.TypeBuilder{ @@ -1417,7 +2992,7 @@ func file_python_ast_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_python_ast_proto_rawDesc, NumEnums: 0, - NumMessages: 15, + NumMessages: 31, NumExtensions: 0, NumServices: 0, }, diff --git a/internal/python/poet/builders.go b/internal/python/poet/builders.go new file mode 100644 index 0000000000..52acf5e0f4 --- /dev/null +++ b/internal/python/poet/builders.go @@ -0,0 +1,90 @@ +package poet + +import "github.com/kyleconroy/sqlc/internal/python/ast" + +func Alias(name string) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Alias{ + Alias: &ast.Alias{ + Name: name, + }, + }, + } +} + +func Await(value *ast.Node) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Await{ + Await: &ast.Await{ + Value: value, + }, + }, + } +} + +func Attribute(value *ast.Node, attr string) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Attribute{ + Attribute: &ast.Attribute{ + Value: value, + Attr: attr, + }, + }, + } +} + +func Comment(text string) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Comment{ + Comment: &ast.Comment{ + Text: text, + }, + }, + } +} + +func Expr(value *ast.Node) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Expr{ + Expr: &ast.Expr{ + Value: value, + }, + }, + } +} + +func Is() *ast.Node { + return &ast.Node{ + Node: &ast.Node_Is{ + Is: &ast.Is{}, + }, + } +} + +func Name(id string) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Name{ + Name: &ast.Name{Id: id}, + }, + } +} + +func Return(value *ast.Node) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Return{ + Return: &ast.Return{ + Value: value, + }, + }, + } +} + +func Yield(value *ast.Node) *ast.Node { + return &ast.Node{ + Node: &ast.Node_Yield{ + Yield: &ast.Yield{ + Value: value, + }, + }, + } +} diff --git a/internal/python/poet/poet.go b/internal/python/poet/poet.go new file mode 100644 index 0000000000..f976ecb7ee --- /dev/null +++ b/internal/python/poet/poet.go @@ -0,0 +1,213 @@ +package poet + +import ( + "github.com/kyleconroy/sqlc/internal/python/ast" +) + +type proto interface { + ProtoMessage() +} + +func Nodes(nodes ...proto) []*ast.Node { + list := make([]*ast.Node, len(nodes)) + for i, _ := range nodes { + list[i] = Node(nodes[i]) + } + return list +} + +func Node(node proto) *ast.Node { + switch n := node.(type) { + + case *ast.Alias: + return &ast.Node{ + Node: &ast.Node_Alias{ + Alias: n, + }, + } + + case *ast.Await: + return &ast.Node{ + Node: &ast.Node_Await{ + Await: n, + }, + } + + case *ast.AnnAssign: + return &ast.Node{ + Node: &ast.Node_AnnAssign{ + AnnAssign: n, + }, + } + + case *ast.Assign: + return &ast.Node{ + Node: &ast.Node_Assign{ + Assign: n, + }, + } + + case *ast.AsyncFor: + return &ast.Node{ + Node: &ast.Node_AsyncFor{ + AsyncFor: n, + }, + } + + case *ast.AsyncFunctionDef: + return &ast.Node{ + Node: &ast.Node_AsyncFunctionDef{ + AsyncFunctionDef: n, + }, + } + + case *ast.Attribute: + return &ast.Node{ + Node: &ast.Node_Attribute{ + Attribute: n, + }, + } + + case *ast.Call: + return &ast.Node{ + Node: &ast.Node_Call{ + Call: n, + }, + } + + case *ast.ClassDef: + return &ast.Node{ + Node: &ast.Node_ClassDef{ + ClassDef: n, + }, + } + + case *ast.Comment: + return &ast.Node{ + Node: &ast.Node_Comment{ + Comment: n, + }, + } + + case *ast.Compare: + return &ast.Node{ + Node: &ast.Node_Compare{ + Compare: n, + }, + } + + // case *ast.Constant: + + // case *ast.Dict: + + case *ast.Expr: + return &ast.Node{ + Node: &ast.Node_Expr{ + Expr: n, + }, + } + + case *ast.For: + return &ast.Node{ + Node: &ast.Node_For{ + For: n, + }, + } + + case *ast.FunctionDef: + return &ast.Node{ + Node: &ast.Node_FunctionDef{ + FunctionDef: n, + }, + } + + case *ast.If: + return &ast.Node{ + Node: &ast.Node_If{ + If: n, + }, + } + + // case *ast.Node_Import: + // w.printImport(n.Import, indent) + + // case *ast.Node_ImportFrom: + // w.printImportFrom(n.ImportFrom, indent) + + // case *ast.Node_Is: + // w.print("is") + + // case *ast.Node_Keyword: + // w.printKeyword(n.Keyword, indent) + + case *ast.Module: + return &ast.Node{ + Node: &ast.Node_Module{ + Module: n, + }, + } + + // w.printModule(n.Module, indent) + + // case *ast.Node_Name: + // w.print(n.Name.Id) + + // case *ast.Node_Pass: + // w.print("pass") + + // case *ast.Node_Return: + // w.printReturn(n.Return, indent) + + // case *ast.Node_Subscript: + // w.printSubscript(n.Subscript, indent) + + case *ast.Yield: + return &ast.Node{ + Node: &ast.Node_Yield{ + Yield: n, + }, + } + + default: + panic(n) + } + +} + +func Constant(value interface{}) *ast.Node { + switch n := value.(type) { + case string: + return &ast.Node{ + Node: &ast.Node_Constant{ + Constant: &ast.Constant{ + Value: &ast.Constant_Str{ + Str: n, + }, + }, + }, + } + + case int: + return &ast.Node{ + Node: &ast.Node_Constant{ + Constant: &ast.Constant{ + Value: &ast.Constant_Int{ + Int: int32(n), + }, + }, + }, + } + + case nil: + return &ast.Node{ + Node: &ast.Node_Constant{ + Constant: &ast.Constant{ + Value: &ast.Constant_None{}, + }, + }, + } + + default: + panic("unknown type") + } +} diff --git a/internal/python/printer/printer.go b/internal/python/printer/printer.go index 977dd86b05..db148caff4 100644 --- a/internal/python/printer/printer.go +++ b/internal/python/printer/printer.go @@ -1,6 +1,11 @@ package printer -import "github.com/kyleconroy/sqlc/internal/python/ast" +import ( + "strconv" + "strings" + + "github.com/kyleconroy/sqlc/internal/python/ast" +) type writer struct { options Options @@ -44,9 +49,18 @@ func (w *writer) printNode(node *ast.Node, indent int32) { case *ast.Node_Assign: w.printAssign(n.Assign, indent) + case *ast.Node_AsyncFor: + w.printAsyncFor(n.AsyncFor, indent) + + case *ast.Node_AsyncFunctionDef: + w.printAsyncFunctionDef(n.AsyncFunctionDef, indent) + case *ast.Node_Attribute: w.printAttribute(n.Attribute, indent) + case *ast.Node_Await: + w.printAwait(n.Await, indent) + case *ast.Node_Call: w.printCall(n.Call, indent) @@ -56,27 +70,60 @@ func (w *writer) printNode(node *ast.Node, indent int32) { case *ast.Node_Comment: w.printComment(n.Comment, indent) + case *ast.Node_Compare: + w.printCompare(n.Compare, indent) + case *ast.Node_Constant: w.printConstant(n.Constant, indent) + case *ast.Node_Dict: + w.printDict(n.Dict, indent) + case *ast.Node_Expr: w.printNode(n.Expr.Value, indent) + case *ast.Node_For: + w.printFor(n.For, indent) + + case *ast.Node_FunctionDef: + w.printFunctionDef(n.FunctionDef, indent) + + case *ast.Node_If: + w.printIf(n.If, indent) + case *ast.Node_Import: w.printImport(n.Import, indent) case *ast.Node_ImportFrom: w.printImportFrom(n.ImportFrom, indent) + case *ast.Node_ImportGroup: + w.printImportGroup(n.ImportGroup, indent) + + case *ast.Node_Is: + w.print("is") + + case *ast.Node_Keyword: + w.printKeyword(n.Keyword, indent) + case *ast.Node_Module: w.printModule(n.Module, indent) case *ast.Node_Name: w.print(n.Name.Id) + case *ast.Node_Pass: + w.print("pass") + + case *ast.Node_Return: + w.printReturn(n.Return, indent) + case *ast.Node_Subscript: w.printSubscript(n.Subscript, indent) + case *ast.Node_Yield: + w.printYield(n.Yield, indent) + default: panic(n) @@ -95,9 +142,17 @@ func (w *writer) printAnnAssign(aa *ast.AnnAssign, indent int32) { w.printNode(aa.Annotation, indent) } +func (w *writer) printArg(a *ast.Arg, indent int32) { + w.print(a.Arg) + if a.Annotation != nil { + w.print(": ") + w.printNode(a.Annotation, indent) + } +} + func (w *writer) printAssign(a *ast.Assign, indent int32) { for i, name := range a.Targets { - w.printName(name, indent) + w.printNode(name, indent) if i != len(a.Targets)-1 { w.print(", ") } @@ -106,15 +161,62 @@ func (w *writer) printAssign(a *ast.Assign, indent int32) { w.printNode(a.Value, indent) } +func (w *writer) printAsyncFor(n *ast.AsyncFor, indent int32) { + w.print("async ") + w.printFor(&ast.For{ + Target: n.Target, + Iter: n.Iter, + Body: n.Body, + }, indent) +} + +func (w *writer) printAsyncFunctionDef(afd *ast.AsyncFunctionDef, indent int32) { + w.print("async ") + w.printFunctionDef(&ast.FunctionDef{ + Name: afd.Name, + Args: afd.Args, + Body: afd.Body, + Returns: afd.Returns, + }, indent) +} + func (w *writer) printAttribute(a *ast.Attribute, indent int32) { - w.printName(a.Value, indent) + if _, ok := a.Value.Node.(*ast.Node_Await); ok { + w.print("(") + w.printNode(a.Value, indent) + w.print(")") + } else { + w.printNode(a.Value, indent) + } w.print(".") w.print(a.Attr) } +func (w *writer) printAwait(n *ast.Await, indent int32) { + w.print("await ") + w.printNode(n.Value, indent) +} + func (w *writer) printCall(c *ast.Call, indent int32) { w.printNode(c.Func, indent) - w.print("()") + w.print("(") + for i, a := range c.Args { + w.printNode(a, indent) + if i != len(c.Args)-1 { + w.print(", ") + } + } + for _, kw := range c.Keywords { + w.print("\n") + w.printIndent(indent + 1) + w.printKeyword(kw, indent+1) + w.print(",") + } + if len(c.Keywords) > 0 { + w.print("\n") + w.printIndent(indent) + } + w.print(")") } func (w *writer) printClassDef(cd *ast.ClassDef, indent int32) { @@ -137,6 +239,14 @@ func (w *writer) printClassDef(cd *ast.ClassDef, indent int32) { } w.print(":\n") for i, node := range cd.Body { + if i != 0 { + if _, ok := node.Node.(*ast.Node_FunctionDef); ok { + w.print("\n") + } + if _, ok := node.Node.(*ast.Node_AsyncFunctionDef); ok { + w.print("\n") + } + } w.printIndent(indent + 1) // A docstring is a string literal that occurs as the first // statement in a module, function, class, or method @@ -145,9 +255,9 @@ func (w *writer) printClassDef(cd *ast.ClassDef, indent int32) { if i == 0 { if e, ok := node.Node.(*ast.Node_Expr); ok { if c, ok := e.Expr.Value.Node.(*ast.Node_Constant); ok { - w.print(`"""`) - w.print(c.Constant.Value) - w.print(`"""`) + w.print(`""`) + w.printConstant(c.Constant, indent) + w.print(`""`) w.print("\n") continue } @@ -159,9 +269,25 @@ func (w *writer) printClassDef(cd *ast.ClassDef, indent int32) { } func (w *writer) printConstant(c *ast.Constant, indent int32) { - w.print("\"") - w.print(c.Value) - w.print("\"") + switch n := c.Value.(type) { + case *ast.Constant_Int: + w.print(strconv.Itoa(int(n.Int))) + + case *ast.Constant_None: + w.print("None") + + case *ast.Constant_Str: + str := `"` + if strings.Contains(n.Str, "\n") { + str = `"""` + } + w.print(str) + w.print(n.Str) + w.print(str) + + default: + panic(n) + } } func (w *writer) printComment(c *ast.Comment, indent int32) { @@ -170,6 +296,115 @@ func (w *writer) printComment(c *ast.Comment, indent int32) { w.print("\n") } +func (w *writer) printCompare(c *ast.Compare, indent int32) { + w.printNode(c.Left, indent) + w.print(" ") + for _, node := range c.Ops { + w.printNode(node, indent) + w.print(" ") + } + for _, node := range c.Comparators { + w.printNode(node, indent) + } +} + +func (w *writer) printDict(d *ast.Dict, indent int32) { + if len(d.Keys) != len(d.Values) { + panic(`dict keys and values are not the same length`) + } + w.print("{") + split := len(d.Keys) > 3 + keyIndent := indent + if split { + keyIndent += 1 + } + for i, _ := range d.Keys { + if split { + w.print("\n") + w.printIndent(keyIndent) + } + w.printNode(d.Keys[i], keyIndent) + w.print(": ") + w.printNode(d.Values[i], keyIndent) + if i != len(d.Keys)-1 || split { + if split { + w.print(",") + } else { + w.print(", ") + } + } + } + if split { + w.print("\n") + w.printIndent(indent) + } + w.print("}") +} + +func (w *writer) printFor(n *ast.For, indent int32) { + w.print("for ") + w.printNode(n.Target, indent) + w.print(" in ") + w.printNode(n.Iter, indent) + w.print(":\n") + for i, node := range n.Body { + w.printIndent(indent + 1) + w.printNode(node, indent+1) + if i != len(n.Body)-1 { + w.print("\n") + } + } +} + +func (w *writer) printIf(i *ast.If, indent int32) { + w.print("if ") + w.printNode(i.Test, indent) + w.print(":\n") + for j, node := range i.Body { + w.printIndent(indent + 1) + w.printNode(node, indent+1) + if j != len(i.Body)-1 { + w.print("\n") + } + } +} + +func (w *writer) printFunctionDef(fd *ast.FunctionDef, indent int32) { + w.print("def ") + w.print(fd.Name) + w.print("(") + if fd.Args != nil { + for i, arg := range fd.Args.Args { + w.printArg(arg, indent) + if i != len(fd.Args.Args)-1 { + w.print(", ") + } + } + if len(fd.Args.KwOnlyArgs) > 0 { + w.print(", *, ") + for i, arg := range fd.Args.KwOnlyArgs { + w.printArg(arg, indent) + if i != len(fd.Args.KwOnlyArgs)-1 { + w.print(", ") + } + } + } + } + w.print(")") + if fd.Returns != nil { + w.print(" -> ") + w.printNode(fd.Returns, indent) + } + w.print(":\n") + for i, node := range fd.Body { + w.printIndent(indent + 1) + w.printNode(node, indent+1) + if i != len(fd.Body)-1 { + w.print("\n") + } + } +} + func (w *writer) printImport(imp *ast.Import, indent int32) { w.print("import ") for i, node := range imp.Names { @@ -194,12 +429,45 @@ func (w *writer) printImportFrom(imp *ast.ImportFrom, indent int32) { w.print("\n") } +func (w *writer) printImportGroup(n *ast.ImportGroup, indent int32) { + if len(n.Imports) == 0 { + return + } + for _, node := range n.Imports { + w.printNode(node, indent) + } + w.print("\n") +} + +func (w *writer) printIs(i *ast.Is, indent int32) { + w.print("is") +} +func (w *writer) printKeyword(k *ast.Keyword, indent int32) { + w.print(k.Arg) + w.print("=") + w.printNode(k.Value, indent) +} + func (w *writer) printModule(mod *ast.Module, indent int32) { - for _, node := range mod.Body { - if _, ok := node.Node.(*ast.Node_ClassDef); ok { - w.print("\n\n") + for i, node := range mod.Body { + prevIsImport := false + if i > 0 { + _, isImport := mod.Body[i-1].Node.(*ast.Node_ImportGroup) + prevIsImport = isImport + } + _, isClassDef := node.Node.(*ast.Node_ClassDef) + _, isAssign := node.Node.(*ast.Node_Assign) + if isClassDef || isAssign { + if prevIsImport { + w.print("\n") + } else { + w.print("\n\n") + } } w.printNode(node, indent) + if isAssign { + w.print("\n") + } } } @@ -207,6 +475,11 @@ func (w *writer) printName(n *ast.Name, indent int32) { w.print(n.Id) } +func (w *writer) printReturn(r *ast.Return, indent int32) { + w.print("return ") + w.printNode(r.Value, indent) +} + func (w *writer) printSubscript(ss *ast.Subscript, indent int32) { w.printName(ss.Value, indent) w.print("[") @@ -214,3 +487,8 @@ func (w *writer) printSubscript(ss *ast.Subscript, indent int32) { w.print("]") } + +func (w *writer) printYield(n *ast.Yield, indent int32) { + w.print("yield ") + w.printNode(n.Value, indent) +} diff --git a/internal/python/printer/printer_test.go b/internal/python/printer/printer_test.go index 6237819b95..41615926ef 100644 --- a/internal/python/printer/printer_test.go +++ b/internal/python/printer/printer_test.go @@ -20,13 +20,19 @@ func TestPrinter(t *testing.T) { Node: &ast.Node{ Node: &ast.Node_Assign{ Assign: &ast.Assign{ - Targets: []*ast.Name{ - {Id: "FICTION"}, + Targets: []*ast.Node{ + { + Node: &ast.Node_Name{ + Name: &ast.Name{Id: "FICTION"}, + }, + }, }, Value: &ast.Node{ Node: &ast.Node_Constant{ Constant: &ast.Constant{ - Value: "FICTION", + Value: &ast.Constant_Str{ + Str: "FICTION", + }, }, }, }, @@ -49,8 +55,12 @@ func TestPrinter(t *testing.T) { { Node: &ast.Node_Attribute{ Attribute: &ast.Attribute{ - Value: &ast.Name{Id: "enum"}, - Attr: "Enum", + Value: &ast.Node{ + Node: &ast.Node_Name{ + Name: &ast.Name{Id: "enum"}, + }, + }, + Attr: "Enum", }, }, }, diff --git a/protos/python/ast.proto b/protos/python/ast.proto index 2f1d8fac7f..d997c974b6 100644 --- a/protos/python/ast.proto +++ b/protos/python/ast.proto @@ -20,6 +20,22 @@ message Node { Comment comment = 12 [json_name="Comment"]; Expr expr = 13 [json_name="Expr"]; Call call = 14 [json_name="Call"]; + FunctionDef function_def = 15 [json_name="FunctionDef"]; + Arg arg = 16 [json_name="Arg"]; + Arguments arguments = 17 [json_name="Arguments"]; + AsyncFunctionDef async_function_def = 18 [json_name="AsyncFunctionDef"]; + Pass pass = 19 [json_name="Pass"]; + Dict dict = 20 [json_name="Dict"]; + If if = 21 [json_name="If"]; + Compare compare = 22 [json_name="Compare"]; + Return return = 23 [json_name="Return"]; + Is is = 24 [json_name="Is"]; + Keyword keyword = 25 [json_name="Keyword"]; + Yield yield = 26 [json_name="Yield"]; + For for = 27 [json_name="For"]; + Await await = 28 [json_name="Await"]; + AsyncFor async_for = 29 [json_name="AsyncFor"]; + ImportGroup import_group = 30 [json_name="ImportGroup"]; } } @@ -28,9 +44,14 @@ message Alias string name = 1 [json_name="name"]; } +message Await +{ + Node value = 1 [json_name="value"]; +} + message Attribute { - Name value = 1 [json_name="value"]; + Node value = 1 [json_name="value"]; string attr = 2 [json_name="attr"]; } @@ -42,9 +63,36 @@ message AnnAssign string Comment = 4 [json_name="comment"]; } +message Arg +{ + string arg = 1 [json_name="arg"]; + Node annotation = 2 [json_name="annotation"]; +} + +message Arguments +{ + repeated Arg args = 1 [json_name="args"]; + repeated Arg kw_only_args = 2 [json_name="kwonlyargs"]; +} + +message AsyncFor +{ + Node target = 1 [json_name="target"]; + Node iter = 2 [json_name="iter"]; + repeated Node body = 3 [json_name="body"]; +} + +message AsyncFunctionDef +{ + string name = 1 [json_name="name"]; + Arguments Args = 2 [json_name="args"]; + repeated Node body = 3 [json_name="body"]; + Node returns = 4 [json_name="returns"]; +} + message Assign { - repeated Name targets = 1 [json_name="targets"]; + repeated Node targets = 1 [json_name="targets"]; Node value = 2 [json_name="value"]; string Comment = 3 [json_name="comment"]; } @@ -52,6 +100,8 @@ message Assign message Call { Node func = 1 [json_name="func"]; + repeated Node args = 2 [json_name="args"]; + repeated Keyword keywords = 3 [json_name="keywords"]; } message ClassDef @@ -70,9 +120,26 @@ message Comment string text = 1 [json_name="text"]; } +message Compare +{ + Node left = 1 [json_name="left"]; + repeated Node ops = 2 [json_name="ops"]; + repeated Node comparators = 3 [json_name="comparators"]; +} + message Constant { - string value = 1 [json_name="value"]; + oneof value { + string str = 1 [json_name="string"]; + int32 int = 2 [json_name="int"]; + bool none = 3 [json_name="none"]; + } +} + +message Dict +{ + repeated Node keys = 1 [json_name="keys"]; + repeated Node values = 2 [json_name="values"]; } message Expr @@ -80,6 +147,28 @@ message Expr Node value = 1 [json_name="value"]; } +message For +{ + Node target = 1 [json_name="target"]; + Node iter = 2 [json_name="iter"]; + repeated Node body = 3 [json_name="body"]; +} + +message FunctionDef +{ + string name = 1 [json_name="name"]; + Arguments Args = 2 [json_name="args"]; + repeated Node body = 3 [json_name="body"]; + Node returns = 4 [json_name="returns"]; +} + +message If +{ + Node test = 1 [json_name="test"]; + repeated Node body = 2 [json_name="body"]; + repeated Node or_else = 3 [json_name="orelse"]; +} + message Import { repeated Node names = 1 [json_name="names"]; @@ -92,6 +181,33 @@ message ImportFrom int32 level = 3 [json_name="level"]; } +// Imports are always put at the top of the file, just after any module +// comments and docstrings, and before module globals and constants. +// +// Imports should be grouped in the following order: +// +// Standard library imports. +// Related third party imports. +// Local application/library specific imports. +// +// You should put a blank line between each group of imports. +// +// https://www.python.org/dev/peps/pep-0008/#imports +message ImportGroup +{ + repeated Node imports = 1 [json_name="imports"]; +} + +message Is +{ +} + +message Keyword +{ + string arg = 1 [json_name="arg"]; + Node value = 2 [json_name="value"]; +} + message Module { repeated Node body = 1 [json_name="body"]; @@ -102,8 +218,25 @@ message Name string id = 1 [json_name="id"]; } +message Pass +{ +} + +message Return +{ + Node value = 1 [json_name="value"]; +} + + message Subscript { Name value = 1 [json_name="value"]; Node slice = 2 [json_name="slice"]; } + +message Yield +{ + Node value = 1 [json_name="value"]; +} + +