The project I work on defines a number of starlark builtins with parameter types not quite supported by starlark.UnpackArgs, e.g., we want an argument of type Union[None|str], or Union[str|List[str]].
Right now, we're unpacking these args into a variable of type starlark.Value and then doing post-unpack validation / casting, which seems like a lot of distracting noise in the builtin definitions.
A solution that comes to mind is to add a new interface starlark.Unpackable with the method Unpack(starlark.Value, ptr interface{}), and have unpackOneArg's switch statement call that if it exists.
This would allow us to have UnpackArgs handle arg validation for custom types as it already does for default types.
I'm happy to write this, but wanted to check on interest or alternatives before doing so.
The project I work on defines a number of starlark builtins with parameter types not quite supported by
starlark.UnpackArgs
, e.g., we want an argument of typeUnion[None|str]
, orUnion[str|List[str]]
.Right now, we're unpacking these args into a variable of type
starlark.Value
and then doing post-unpack validation / casting, which seems like a lot of distracting noise in the builtin definitions.A solution that comes to mind is to add a new interface
starlark.Unpackable
with the methodUnpack(starlark.Value, ptr interface{})
, and haveunpackOneArg
's switch statement call that if it exists.This would allow us to have UnpackArgs handle arg validation for custom types as it already does for default types.
I'm happy to write this, but wanted to check on interest or alternatives before doing so.
Thanks!