aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-07-19 19:50:22 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-07-20 10:29:02 +0200
commit54feda55ebf10198a979f4546f684fa8b51c6fb8 (patch)
treeacaa5bb2acbb6bf66576e87479c654b8bcc5ac42 /src
parent978780d6d4432d46199331bd8dae34ce10dab067 (diff)
Update documentation of `dict`, mention it's mutable.
RELNOTES: None. PiperOrigin-RevId: 162505701
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
index 08318226b5..40c9c9ddb3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkDict.java
@@ -31,13 +31,15 @@ import javax.annotation.Nullable;
"A language built-in type representating a dictionary (associative mapping). "
+ "Dictionaries may be constructed with a special literal syntax:<br>"
+ "<pre class=\"language-python\">d = {\"a\": 2, \"b\": 5}</pre>"
+ + "See also the <a href=\"globals.html#dict\">dict()</a> constructor function. "
+ "When using the literal syntax, it is an error to have duplicated keys. "
+ "Use square brackets to access elements:<br>"
+ "<pre class=\"language-python\">e = d[\"a\"] # e == 2</pre>"
+ "Like lists, they can also be constructed using a comprehension syntax:<br>"
+ "<pre class=\"language-python\">d = {i: 2*i for i in range(20)}\n"
+ "e = d[8] # e == 16</pre>"
- + "See also the <a href=\"globals.html#dict\">dict()</a> constructor function. "
+ + "Dictionaries are mutable. You can add new elements or mutate existing ones:"
+ + "<pre class=\"language-python\">d[\"key\"] = 5</pre>"
+ "<p>Iterating over a dict is equivalent to iterating over its keys. The "
+ "<code>in</code> operator tests for membership in the keyset of the dict.<br>"
+ "<pre class=\"language-python\">\"a\" in {\"a\" : 2, \"b\" : 5} "