Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check the type like Python? #266

Open
ThreadSanitizer opened this issue Sep 20, 2023 · 2 comments
Open

check the type like Python? #266

ThreadSanitizer opened this issue Sep 20, 2023 · 2 comments

Comments

@ThreadSanitizer
Copy link

For example:

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

How to do this in Starlark?

@stepancheg
Copy link
Contributor

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.

@brandjon
Copy link
Member

Any kind of symbolic type check raises questions about what exactly is a type, and what the type hierarchy is. Off the top of my head:

  • Would isinstance() work on bazel providers and their instances?
  • If you had a type()-style function that returned a type object, could that result be used to construct an instance of the type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants