Skip to content

Commit

Permalink
Fix type detection, changing order of Set and Module checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
voutilad committed Aug 22, 2024
1 parent 719e000 commit a502384
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ print(f"helper module executed, __name__={__name__}")

var program = `
import example.junk as junk
def findme():
return "hello"
root = {
"long": 123,
"list": [],
Expand All @@ -40,16 +44,15 @@ root = {
"float": 3.14,
"set": set(),
"none": None,
"module": junk,
"function": findme,
}
# trigger a callback
go_func(0, 1, 2)
j = junk.Junk()
def findme():
return "hello"
def _genny():
yield "hello"
genny = _genny()
Expand Down Expand Up @@ -245,22 +248,25 @@ func main() {
log.Fatalln("root should be a dict")
}
m := map[string]py.Type{
"long": py.Long,
"list": py.List,
"tuple": py.Tuple,
"bytes": py.Bytes,
"string": py.String,
"float": py.Float,
"set": py.Set,
"none": py.None,
"long": py.Long,
"list": py.List,
"tuple": py.Tuple,
"bytes": py.Bytes,
"string": py.String,
"float": py.Float,
"set": py.Set,
"module": py.Module,
"function": py.Function,
"none": py.None,
}
for k, v := range m {
obj := py.PyDict_GetItemString(root, k)
if obj == py.NullPyObjectPtr {
log.Fatalf("Failed to find key %s in root dict\n", k)
}
if py.BaseType(obj) != v {
log.Fatalf("Value for key %s is not %s\n", k, v.String())
log.Fatalf("Value for key %s is not %s, got %s\n", k, v.String(),
py.BaseType(obj).String())
}
log.Printf("Detected root['%s'] as a %s\n", k, v.String())
}
Expand Down
6 changes: 3 additions & 3 deletions gogopython.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ func BaseType(obj PyObjectPtr) Type {
if (flags & genMask) == genMask {
return Generator
}
if (flags & moduleMask) == moduleMask {
return Module
}
if (flags & setMask) == setMask {
return Set
}
if (flags & moduleMask) == moduleMask {
return Module
}
if (flags & floatMask) == floatMask {
return Float
}
Expand Down

0 comments on commit a502384

Please sign in to comment.