Skip to content

Commit

Permalink
if renaming case, use lower-case string() method instead of String() --
Browse files Browse the repository at this point in the history
fixes #337
  • Loading branch information
rcoreilly committed Apr 22, 2024
1 parent 4aba380 commit 9dde376
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions bind/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,13 @@ func (g *pyGen) genGoPkg() {
g.genType(sym, false, false) // not exttypes
}
}

// genStringerCall generates a call to either self.String() or self.string()
// depending on RenameCase option
func (g *pyGen) genStringerCall() {
if g.cfg.RenameCase {
g.pywrap.Printf("return self.string()\n")
} else {
g.pywrap.Printf("return self.String()\n")
}
}
2 changes: 1 addition & 1 deletion bind/gen_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ otherwise parameter is a python list that we copy from
if isStringer(m.obj) {
g.pywrap.Printf("def __str__(self):\n")
g.pywrap.Indent()
g.pywrap.Printf("return self.String()\n")
g.genStringerCall()
g.pywrap.Outdent()
g.pywrap.Printf("\n")
}
Expand Down
2 changes: 1 addition & 1 deletion bind/gen_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ otherwise parameter is a python list that we copy from
if isStringer(m.obj) {
g.pywrap.Printf("def __str__(self):\n")
g.pywrap.Indent()
g.pywrap.Printf("return self.String()\n")
g.genStringerCall()
g.pywrap.Outdent()
}
}
Expand Down
4 changes: 2 additions & 2 deletions bind/gen_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ in which case a new Go object is constructed first
}
g.pywrap.Printf("def __str__(self):\n")
g.pywrap.Indent()
g.pywrap.Printf("return self.String()\n")
g.genStringerCall()
g.pywrap.Outdent()
g.pywrap.Printf("\n")
}
Expand Down Expand Up @@ -345,7 +345,7 @@ handle=A Go-side object is always initialized with an explicit handle=arg
}
g.pywrap.Printf("def __str__(self):\n")
g.pywrap.Indent()
g.pywrap.Printf("return self.String()\n")
g.genStringerCall()
g.pywrap.Outdent()
g.pywrap.Printf("\n")
}
Expand Down

0 comments on commit 9dde376

Please sign in to comment.