starlark icon indicating copy to clipboard operation
starlark copied to clipboard

check the type like Python?

Open ThreadSanitizer opened this issue 2 years ago • 1 comments
trafficstars

For example:

>>> x = 123
>>> type(x) is int
True
>>> type(x) is str
False
>>>

How to do this in Starlark?

ThreadSanitizer avatar Sep 20 '23 16:09 ThreadSanitizer

In starlark spec starlark, the way to do it is:

type(x) == type(1)

in starlark-rust we have isinstance:

isinstance(x, int)

which I thing might be helpful addition to starlark spec, some basic form, i.e. mandate isinstance should work for builtin constructors like int or list.

stepancheg avatar Sep 21 '23 10:09 stepancheg