from __future__ import annotations import typing as t from emit import emit, metadata, field from prestring.go.gofmt import gofmt class Person: name: str age: int memo: Memo = field(metadata=metadata(inline=True)) class Memo: data: t.Dict[str, t.Any] print(gofmt(emit([Person]), always=False))
# https://eli.thegreenplace.net/2018/go-and-algebraic-data-types/ from __future__ import annotations import typing as t from prestring.go.gofmt import gofmt from emit import emit, field, metadata class Empty: pass class Leaf: value: int class Node: left: Tree right: Tree Tree = t.Union[Empty, Leaf, Node] Tree.__name__ = "Tree" print(gofmt(emit([Tree]), always=False))
from __future__ import annotations import typing as t from emit import emit from prestring.go.gofmt import gofmt class Atom: type_: str class Composite: type_: str args: t.List[Node] Node = t.Union[Atom, Composite] Node.__name__ = "Node" print(gofmt(emit([Node]), always=False))
from emit import emit from prestring.go.gofmt import gofmt class A: x: int y: int class B(A): y: str z: str print(gofmt(emit([B]), always=False))