-
Notifications
You must be signed in to change notification settings - Fork 165
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
Spec incorrectly claims that predeclared bindings cannot be reassigned #282
Comments
There is shadowing. Values in the "predeclared" block can be shadowed by values in the module or file block. It's all resolved statically (unlike Python). Indeed, this was designed with backwards compatibility in mind. |
Ah, my bad. I can see how this is considered to be shadowing rather than rebinding. A note to clarify could help, but I see now that this is not a bug in the spec. |
The spec mentions later:
But I agree that the first quote can cause confusion. On a side-note, this code shows the difference with Python: print(len)
len = 2 Python3 will print |
Thanks for the explanation. I found another issue -- running it by you here before I open another issue, in case I'm misunderstanding again. The spec says:
I take this to mean that the following Starlark should be rejected: # In a .bzl file, this code is rejected.
# In a BUILD file, it prints "3"
load(":test.bzl", "a")
a = 3
print(a) In my testing, I find that this fragment is rejected in a |
Correct, this should be rejected. When we decided on this behavior, there were many existing BUILD files, so we added an exception for them and postponed the migration. Ideally, a migration flag should be added to Bazel and later switched. It's worth filing an issue on Bazel. |
That makes sense. I also notice that the spec makes no mention of the leading-underscore-is-private convention used by Bazel. I guess this is already mentioned in #37. |
See https://github.com/bazelbuild/starlark/blob/master/spec.md#load-statements
|
In the Name binding and variables section, it says:
However both Bazel and https://github.com/google/starlark-go allow reassignment of
True
:I initially considered this to be a bug in the implementations rather than the spec, since it seems like a good idea to prevent rebinding of the predeclared names. But then I realized that this would make it impossible to add new predeclared names in a backwards-compatible way. So perhaps this is a necessary evil.
The text was updated successfully, but these errors were encountered: