-
Notifications
You must be signed in to change notification settings - Fork 163
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
dict.update should return None, not self #18
Comments
Thanks! |
In .bzl files, the expression dict(a=1).update(b=2) evaluates to {a: 1,
b: 2}
How does it do that? The bug is that dict.update doesn't take entries as
**kargs, so shouldn't that fail as per the example you gave?
…On Thu, Nov 29, 2018 at 6:44 PM Laurent Le Brun ***@***.***> wrote:
Thanks!
That's a bug in Bazel.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABP1phtFT0XxLPhigdLCTycR2bje5RHzks5u0HFlgaJpZM4Y6uHs>
.
|
Error message is bad, but the If you do: cr/223363742 boils down to: SomeInfo = provider(
fields = {
"...": "...",
}.update(other_fields), This is confusing, because update returns None. In other words, the dictionary is created, modified and thrown away. |
So it seems like the resolution is to make the Java impl and its doc match what the spec doc says:
Yes, it's an easy trap to fall into. Do you have a lint check for it? The deprecated {} + {} wasn't so bad after all. :( |
Right. Good enough, it's just a new feature and not a breaking change. In the future, we can indeed extend the linter to catch this kind of things. Right now, we focus on the deprecated features, and help users migrate their code. |
Closes [dict.update should return None, not self #18](bazelbuild/starlark#18) dict.update() method should now accept keyword args just like dict(...) **Example of usage:** ``` >> a = dict(a=1) .. >> a.update(b=2) .. None >> a.update({'c': 3}) .. None >> a .. {"a": 1, "b": 2, "c": 3} ``` Closes #7684. PiperOrigin-RevId: 239018051
Fixed in Bazel |
In particular, add tests with both a positional argument and keyword arguments (to show that the keyword arguments win). bazelbuild/starlark#18 RELNOTES: None. PiperOrigin-RevId: 239024409
In .bzl files, the expression dict(a=1).update(b=2) evaluates to {a: 1, b: 2} but according to
https://github.com/bazelbuild/starlark/blob/master/spec.md#dictupdate
it should return None.
Both Pythons and Starlark-in-Go return None:
$ python # 2 or 3
$ starlark # in Go
The Java standalone interpreter gives a strange error --- I have no idea what it means:
% blaze-bin/third_party/bazel/src/main/java/com/google/devtools/skylark/Skylark
Googlers: see L23 of dart_dev_ctx.bzl in cr/223363742 for a real-world example.
The text was updated successfully, but these errors were encountered: