go-python / gopy

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

Can't return a slice of slices ([][]bool) #346

Closed moritz157 closed 6 months ago

moritz157 commented 9 months ago

I wanted to pass a slice of slices of boolean values ([][]bool). I would assume that this could simply be done like this:

func GetEmptyMatrix(xSize int, ySize int) [][]bool {
    result := [][]bool{}

    for i := 0; i < xSize; i++ {
        result = append(result, []bool{})
        for j := 0; j < ySize; j++ {
            result[i] = append(result[i], false)
        }
    }

    return result
}

In Python I then simply called the function:

from out import matrix

matrix.GetEmptyMatrix(4,4)

However, this failed with the following error: panic: interface conversion: interface {} is []bool, not *[]bool

Is passing a slice of slices generally not supported or do I have to do it in a different way (like passing a slice of pointers to slices)? If this is supported, I would suggest to maybe add an example for this because as far as I can see, there is none yet. If I'm just doing it wrong, a hint in the right direction would be greatly appreciated :)

richecr commented 9 months ago

This problem has similarities to this.

rcoreilly commented 6 months ago

I'm assuming this is now fixed by #350 unless someone tells me otherwise. And if someone could write a test to confirm, that would be most appreciated (@EvanOman ?)

EvanOman commented 6 months ago

@rcoreilly No, my previous PR did not fix slices, only maps

However I just added #351 which fixes this issue and adds a test based on the example from @moritz157