python-starlark-go icon indicating copy to clipboard operation
python-starlark-go copied to clipboard

Support struct

Open n87 opened this issue 2 years ago • 4 comments

It'd be great to have struct datatype supported. The implementation is in starlark-go repo, but seems not enabled by default: https://github.com/google/starlark-go/tree/master/starlarkstruct

Conversion to/from Python values can be done either by writing new class, or reusing namedtuple. With namedtuple, you have to take care of builtin index() and count() methods. Also to check that object is a named tuple, you can check that it's an instance of tuple and has _fields:

isinstance(x, tuple) and hasattr(x, '_fields')

Go is not my area of competence, but I could help with Python side of things.

n87 avatar Feb 26 '23 09:02 n87