aboutsummaryrefslogtreecommitdiffhomepage
path: root/site/docs/skylark/concepts.md
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-07-12 22:12:04 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-07-13 09:56:32 +0200
commita752d8b83ff3a241076b121dff989eb3def9cfb6 (patch)
tree2c8919801d13f1c7306a11ef3352461eb87e5338 /site/docs/skylark/concepts.md
parent5f36bf8a0716434348042c088da838728dc6dcdc (diff)
New flag --incompatible_string_is_not_iterable to forbid iteration over strings.
RELNOTES: None. PiperOrigin-RevId: 161706309
Diffstat (limited to 'site/docs/skylark/concepts.md')
-rw-r--r--site/docs/skylark/concepts.md35
1 files changed, 32 insertions, 3 deletions
diff --git a/site/docs/skylark/concepts.md b/site/docs/skylark/concepts.md
index 040654fe64..f2f80437f7 100644
--- a/site/docs/skylark/concepts.md
+++ b/site/docs/skylark/concepts.md
@@ -238,9 +238,9 @@ comprehension.
When the flag is set to true, `depset` objects are not treated as iterable. If
you need an iterable, call the `.to_list()` method. This affects `for` loops and
-many functions, e.g. `list`, `tuple`, `min`, `max`, `sorted`, `all`, `any`. The
-goal of this change is to avoid accidental iteration on `depset`, which can be
-expensive.
+many functions, e.g. `list`, `tuple`, `min`, `max`, `sorted`, `all`, and `any`.
+The goal of this change is to avoid accidental iteration on `depset`, which can
+be expensive.
``` python
deps = depset()
@@ -255,6 +255,35 @@ sorted(deps.to_list()) # recommended
* Default: `false`
+### String is no longer iterable
+
+When the flag is set to true, `string` objects are not treated as iterable. This
+affects `for` loops and many functions, e.g. `list`, `tuple`, `min`, `max`,
+`sorted`, `all`, and `any`. String iteration has been a source of errors and
+confusion, such as this error:
+
+``` python
+def my_macro(name, srcs):
+ for src in srcs:
+ # do something with src
+
+my_macro("foo") # equivalent to: my_macro(["f", "o", "o"])
+```
+
+String indexing and `len` are still allowed. If you need to iterate over a
+string, you may explicitly use:
+
+``` python
+my_string="hello world"
+for i in range(len(my_string)):
+ char = my_string[i]
+ # do something with char
+```
+
+* Flag: `--incompatible_string_is_not_iterable`
+* Default: `false`
+
+
### Dictionary literal has no duplicates
When the flag is set to true, duplicated keys are not allowed in the dictionary