Skip to content

Commit f993dc7

Browse files
committed
Make nil items return as None
1 parent 216cff9 commit f993dc7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

ast/dump.go

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
)
1010

1111
func dumpItem(v interface{}) string {
12+
if v == nil {
13+
return "None"
14+
}
1215
switch x := v.(type) {
1316
case py.String:
1417
return fmt.Sprintf("'%s'", string(x))

ast/dump_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestDump(t *testing.T) {
2525
{&Name{Id: Identifier("hello"), Ctx: Load}, `Name(id='hello', ctx=Load())`},
2626
{&ListComp{Elt: &Str{S: py.String("potato")}, Generators: []Comprehension{{
2727
Target: &Name{Id: Identifier("hello"), Ctx: Load},
28-
}}}, `ListComp(elt=Str(s='potato'), generators=[comprehension(target=Name(id='hello', ctx=Load()), iter=<nil>, ifs=[])])`},
28+
}}}, `ListComp(elt=Str(s='potato'), generators=[comprehension(target=Name(id='hello', ctx=Load()), iter=None, ifs=[])])`},
2929
} {
3030
out := Dump(test.in)
3131
if out != test.out {

0 commit comments

Comments
 (0)