-
Notifications
You must be signed in to change notification settings - Fork 410
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
Support type annotations #900
Comments
Earlier discussion: https://groups.google.com/d/msg/bazel-dev/Pk9VrPCqby0/zoOL1IkxEAAJ I think there should be a standard way for annotating types in Starlark. This is probably something to discuss in http://github.com/bazelbuild/starlark.
Is there anything public? |
A standard way for annotating types in Starlark would be nice, but is slightly more than I'm aiming for here. Starlark can't gain support for the above form of type annotation, because its not compatible with Python 2. However, if the "extended Starlark" tools (e.g. those with support nested def etc and other non-Starlark features) could merely ignore type annotations, then we could use existing Python type checkers like Pyre or MyPy to check Starlark files.
Not yet, but I hope so in the near/medium term. |
Python 2 compatibility is no longer a concern (bazelbuild/starlark#27). |
Probably not easily, but it doesn't seem infeasible to add knowledge of |
I raised an issue at bazelbuild/starlark#106. |
@vladmos What do you think of allowing type annotations in the parser, maybe behind a flag? |
I think it can be implelented even without a flag, Buildifier already allows things that are not allowed by the interpreter (such as functions in BUILD files). How does the language spec allowing type annotations look like? Compared with the official spec, is it enough and correct to just change the following:
|
https://github.com/facebookexperimental/starlark-rust/blob/master/starlark/src/syntax/grammar.lalrpop#L68 is the grammar we used. Note that because |
The code:
Currently gives:
That code is accepted by
python3
. I think it would be useful to support inbuildifer
in particular because types are an extension that some Starlark implementations support, much the same way that nested-def
is a Starlark extension that is supported by buildifier.If the above is accepted, I'd be happy to do a PR to enable it.
The text was updated successfully, but these errors were encountered: