bazelbuild / starlark

Starlark Language
Apache License 2.0
2.38k stars 158 forks source link

check the type like Python? #266

Open ThreadSanitizer opened 9 months ago

ThreadSanitizer commented 9 months ago

For example:

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

How to do this in Starlark?

stepancheg commented 9 months ago

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.