Skip to content

Commit

Permalink
callable type
Browse files Browse the repository at this point in the history
  • Loading branch information
hyorigo committed Feb 22, 2024
1 parent 87aa89b commit e7006c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dataconv/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,6 @@ func shardDictPerform(thread *starlark.Thread, b *starlark.Builtin, args starlar
case starlark.Callable:
return pr.CallInternal(thread, starlark.Tuple{d}, nil)
default:
return nil, fmt.Errorf("unsupported callable type: %s", pr.Type())
return nil, fmt.Errorf("%s: not callable type: %s", b.Name(), pr.Type())
}
}
24 changes: 24 additions & 0 deletions dataconv/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func TestSharedDict_Functions(t *testing.T) {
assert.eq(sd.len(), 1)
`),
},
{
name: `attr: custom len -- invalid args`,
script: itn.HereDoc(`
load('share', 'sd')
sd.len(123)
`),
wantErr: `len: got 1 arguments, want 0`,
},
{
name: `attr: custom perform`,
script: itn.HereDoc(`
Expand All @@ -215,6 +223,22 @@ func TestSharedDict_Functions(t *testing.T) {
print(sd)
`),
},
{
name: `attr: custom perform -- invalid args`,
script: itn.HereDoc(`
load('share', 'sd')
sd.perform()
`),
wantErr: `perform: missing argument for fn`,
},
{
name: `attr: custom perform -- invalid type`,
script: itn.HereDoc(`
load('share', 'sd')
sd.perform(123)
`),
wantErr: `perform: not callable type: int`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e7006c8

Please sign in to comment.