if renaming case, use lower-case string() method instead of String() -- fixes #337

This commit is contained in:
Randall C. O'Reilly 2024-04-22 16:04:17 -07:00
parent 4aba380925
commit 9dde3761d5
4 changed files with 14 additions and 4 deletions

View File

@ -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")
}
}

View File

@ -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")
}

View File

@ -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()
}
}

View File

@ -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")
}
@ -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")
}