go-python / gopy

gopy generates a CPython extension module from a go package.
BSD 3-Clause "New" or "Revised" License
2.05k stars 113 forks source link

struct field setters for types based on basic types are not recognized as such #220

Closed rcoreilly closed 4 years ago

rcoreilly commented 4 years ago

@cosnicolaou this code in bind/gen_struct.go is somehow not working as expected:

// See comment in genStructInit about ensuring that gopy managed
    // objects are only assigned to from gopy managed objects.
    switch f.Type().(type) {
    case *types.Basic:
        g.pywrap.Printf("_%s.%s(self.handle, value)\n", pkgname, cgoFn)
    default:
        g.pywrap.Printf("raise TypeError(\"supplied argument type {t} is not a go.GoClass\".format(t=type(value)))\n")
    }

for types that are based on Basic types, e.g., type Dim int or type FileName string, this switch is going into the default: case.

I will figure out why and add a PR for this and the --no-warn flag.

cosnicolaou commented 4 years ago

that's most likely because they are of *type.Named. I can send you a fix or code snippet if you wish.