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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy