Skip to content

Commit

Permalink
Switch the default value of --incompatible_range_type
Browse files Browse the repository at this point in the history
#5264

RELNOTES: `range()` function now returns a lazy value (`--incompatible_range_type` is now set by default).
PiperOrigin-RevId: 218920956
  • Loading branch information
laurentlb authored and Copybara-Service committed Oct 26, 2018
1 parent 2290505 commit dec6577
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion site/docs/skylark/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ a `list`. Because of this repetitions using `*` operator are no longer
supported and `range` slices are also lazy `range` instances.

* Flag: `--incompatible_range_type`
* Default: `false`
* Default: `true`
* Tracking issue: [#5264](https://github.com/bazelbuild/bazel/issues/5264)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable

@Option(
name = "incompatible_range_type",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static Builder builderWithDefaults() {
.incompatibleNoTargetOutputGroup(false)
.incompatibleNoTransitiveLoads(false)
.incompatiblePackageNameIsAFunction(false)
.incompatibleRangeType(false)
.incompatibleRangeType(true)
.incompatibleRemoveNativeGitRepository(true)
.incompatibleRemoveNativeHttpArchive(true)
.incompatibleStaticNameResolution(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void testHash() throws Exception {

@Test
public void testRange() throws Exception {
new BothModesTest()
new BothModesTest("--incompatible_range_type=false")
.testStatement("str(range(5))", "[0, 1, 2, 3, 4]")
.testStatement("str(range(0))", "[]")
.testStatement("str(range(1))", "[0]")
Expand Down Expand Up @@ -564,14 +564,14 @@ public void testRangeType() throws Exception {
*/
private void runRangeIsListAssertions(String range3expr) throws Exception {
// Check stringifications.
new BothModesTest()
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.testStatement("str(a)", "[0, 1, 2]")
.testStatement("repr(a)", "[0, 1, 2]")
.testStatement("type(a)", "list");

// Check comparisons.
new BothModesTest()
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.setUp("b = range(0, 3, 1)")
.setUp("c = range(1, 4)")
Expand All @@ -587,10 +587,10 @@ private void runRangeIsListAssertions(String range3expr) throws Exception {
.testIfErrorContains("Cannot compare list with tuple", "a < T");

// Check mutations.
new BothModesTest()
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.testStatement("a.append(3); str(a)", "[0, 1, 2, 3]");
new SkylarkTest()
new SkylarkTest("--incompatible_range_type=false")
.testStatement(
"def f():\n"
+ " a = " + range3expr + "\n"
Expand All @@ -601,7 +601,7 @@ private void runRangeIsListAssertions(String range3expr) throws Exception {
"[0, 1, 2, 3]");

// Check concatenations.
new BothModesTest()
new BothModesTest("--incompatible_range_type=false")
.setUp("a = " + range3expr)
.setUp("b = range(3, 4)")
.setUp("L = [3]")
Expand Down
28 changes: 14 additions & 14 deletions src/test/skylark/testdata/range.sky
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
assert_eq(range(5), [0, 1, 2, 3, 4])
assert_eq(range(0), [])
assert_eq(range(1), [0])
assert_eq(range(-2), [])
assert_eq(range(-3, 2), [-3, -2, -1, 0, 1])
assert_eq(range(3, 2), [])
assert_eq(range(3, 3), [])
assert_eq(range(3, 4), [3])
assert_eq(range(3, 5), [3, 4])
assert_eq(range(-3, 5, 2), [-3, -1, 1, 3])
assert_eq(range(-3, 6, 2), [-3, -1, 1, 3, 5])
assert_eq(range(5, 0, -1), [5, 4, 3, 2, 1])
assert_eq(range(5, 0, -10), [5])
assert_eq(range(0, -3, -2), [0, -2])
assert_eq(list(range(5)), [0, 1, 2, 3, 4])
assert_eq(list(range(0)), [])
assert_eq(list(range(1)), [0])
assert_eq(list(range(-2)), [])
assert_eq(list(range(-3, 2)), [-3, -2, -1, 0, 1])
assert_eq(list(range(3, 2)), [])
assert_eq(list(range(3, 3)), [])
assert_eq(list(range(3, 4)), [3])
assert_eq(list(range(3, 5)), [3, 4])
assert_eq(list(range(-3, 5, 2)), [-3, -1, 1, 3])
assert_eq(list(range(-3, 6, 2)), [-3, -1, 1, 3, 5])
assert_eq(list(range(5, 0, -1)), [5, 4, 3, 2, 1])
assert_eq(list(range(5, 0, -10)), [5])
assert_eq(list(range(0, -3, -2)), [0, -2])

---
range(2, 3, 0) ### step cannot be 0
Expand Down
2 changes: 1 addition & 1 deletion tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def create_system_images_filegroups(system_image_dirs):
system_images = [
(tag, str(api), arch)
for tag in ["android", "google"]
for api in [10] + range(15, 20) + range(21, 29)
for api in [10] + list(range(15, 20)) + list(range(21, 29))
for arch in ("x86", "arm")
]
tv_images = [
Expand Down

0 comments on commit dec6577

Please sign in to comment.