Skip to content

Commit 4ab8fc2

Browse files
committed
Dump Bytes
1 parent 1d99034 commit 4ab8fc2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

ast/dump.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Dump(ast Ast) string {
2424
fieldType := astType.Field(i)
2525
fieldValue := astValue.Field(i)
2626
fname := strings.ToLower(fieldType.Name)
27-
if fieldValue.Kind() == reflect.Slice {
27+
if fieldValue.Kind() == reflect.Slice && fieldValue.Type().Elem().Kind() != reflect.Uint8 {
2828
strs := make([]string, fieldValue.Len())
2929
for i := 0; i < fieldValue.Len(); i++ {
3030
element := fieldValue.Index(i)
@@ -44,6 +44,8 @@ func Dump(ast Ast) string {
4444
switch x := v.(type) {
4545
case py.String:
4646
args = append(args, fmt.Sprintf("%s=%q", fname, string(x)))
47+
case py.Bytes:
48+
args = append(args, fmt.Sprintf("%s=b'%s'", fname, string(x)))
4749
case Identifier:
4850
args = append(args, fmt.Sprintf("%s='%s'", fname, string(x)))
4951
case ModBase:

ast/dump_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func TestDump(t *testing.T) {
1515
{&Pass{}, `Pass()`},
1616
{&Str{S: py.String("potato")}, `Str(s="potato")`},
1717
{&Str{S: py.String("potato")}, `Str(s="potato")`},
18+
{&Bytes{S: py.Bytes("potato")}, `Bytes(s=b'potato')`},
1819
{&BinOp{Left: &Str{S: py.String("one")}, Op: Add, Right: &Str{S: py.String("two")}},
1920
`BinOp(left=Str(s="one"), op=Add(), right=Str(s="two"))`},
2021
{&Module{}, `Module(body=[])`},

0 commit comments

Comments
 (0)