Skip to content

Commit aa058f1

Browse files
committed
Dump py.Objects with __str__ if possible
1 parent adafadd commit aa058f1

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

ast/dump.go

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func Dump(ast Ast) string {
5151
case Pos:
5252
case Ast:
5353
args = append(args, fmt.Sprintf("%s=%s", fname, Dump(x)))
54+
case py.I__str__:
55+
args = append(args, fmt.Sprintf("%s=%s", fname, x.M__str__()))
5456
default:
5557
args = append(args, fmt.Sprintf("%s=%v", fname, x))
5658
}

ast/dump_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestDump(t *testing.T) {
2020
{&Module{}, `Module(body=[])`},
2121
{&Module{Body: []Stmt{&Pass{}}}, `Module(body=[Pass()])`},
2222
{&Module{Body: []Stmt{&ExprStmt{Value: &Tuple{}}}}, `Module(body=[Expr(value=Tuple(elts=[], ctx=UnknownExprContext(0)))])`},
23+
{&NameConstant{Value: py.True}, `NameConstant(value=True)`},
2324
} {
2425
out := Dump(test.in)
2526
if out != test.out {

0 commit comments

Comments
 (0)