Handle negative count arg in string.replace#9228
Handle negative count arg in string.replace#9228zegl wants to merge 5 commits intobazelbuild:masterfrom
Conversation
4cac4a1 to
9545d79
Compare
|
@laurentlb @c-parsons can you take a look? Thanks! |
eded3fd to
e0bbf92
Compare
|
I've rebased and force-pushed to resolve conflicts in |
| doc = "The string to replace with."), | ||
| @Param( | ||
| name = "maxsplit", | ||
| name = "count", |
There was a problem hiding this comment.
I think renaming this would be a breaking change. May need to keep the old name for now.
There was a problem hiding this comment.
Yes, it's clearly breaking! The question is if it's a change that's allowed to be made according to the compatability policy, the Backwards Compatability document does not mention what's allowed and not in these edge cases.
To draw some inspiration from other projects: the Go1 compatability document states:
If a compiler or library has a bug that violates the specification, a program that depends on the buggy behavior may break if the bug is fixed. We reserve the right to fix such bugs.
I think that this is an example of that, as the Starlark implementation in Bazel does not satisfy the spec.
I'll leave it up to you and the team to figure this out, but I do think that it would be nice to allow to make some breaking changes without increasing the major-version number in the future.
There was a problem hiding this comment.
This is definitely a breaking change which is not allowed by our policy -- apologies this is not clear by the policy doc, but this is definitely going to break some users and cause some pain if we change it.
We should avoid renaming this for now.
The parameter is tagged with legacyNamed = true, so, subject to the rollout of #8147, this parameter will be positional-only in the future. We can then rename the parameter safely for documentation purposes.
There was a problem hiding this comment.
To clarify, there's two breaking changes: the rename and the behavior for negative values.
The rename is subsumed by #8147, so we should definitely not do any extra work here. You can add a comment reminding us to get back to it:
// TODO(#8147): rename param to "count" once it's positional-only.
The behavioral change for negatives is also breaking. I feel like it's not very likely people will be broken by it, but it seems like the kind of thing we should guard with a flag. Look for other examples of using incompatible flags in Starlark builtins -- for instance, incompatibleDisableDepsetItems in the depset constructor later in this file, and its corresponding definitions in StarlarkSemantics and StarlarkSemanticsOptions.
There was a problem hiding this comment.
Ok, let's do this the proper way, by marking the negative value behaviour change as breaking.
Other than adding the flag and the handling of it, is there anything else that needs to be done? What's the process for creating issues with the incompatible-change and breaking-change-* labels?
There was a problem hiding this comment.
When you file the GitHub issue, you can cc me so that I add the labels.
If your change is ready this week, we can include it in Bazel 3.2.
Thanks!
There was a problem hiding this comment.
@alandonovan points out to me that we actually already flipped and deleted --incompatible_restrict_named_params, so I'll do the rename as part of the follow-up.
|
Ping |
|
Another ping |
|
@aiuto Are you pinging me? What would be the process of getting this change in now? I'm guessing that it's still not allowed breakage, or is it? |
e0bbf92 to
6a25d31
Compare
|
I resolved the conflicts (Runtime.NONE has been renamed to Starlark.NONE), and fixed the issues found by c-parsons. |
Also update the name of the argument to be "count" instead of "maxsplit", to match the Starlark spec.
6a25d31 to
c8f0e94
Compare
|
Can you take a look at https://www.bazel.build/breaking-changes-guide.html? Thanks! |
|
I was pinging all the stale PRs so we can finish them or close them. |
| doc = "The string to replace with."), | ||
| @Param( | ||
| name = "maxsplit", | ||
| name = "count", |
There was a problem hiding this comment.
To clarify, there's two breaking changes: the rename and the behavior for negative values.
The rename is subsumed by #8147, so we should definitely not do any extra work here. You can add a comment reminding us to get back to it:
// TODO(#8147): rename param to "count" once it's positional-only.
The behavioral change for negatives is also breaking. I feel like it's not very likely people will be broken by it, but it seems like the kind of thing we should guard with a flag. Look for other examples of using incompatible flags in Starlark builtins -- for instance, incompatibleDisableDepsetItems in the depset constructor later in this file, and its corresponding definitions in StarlarkSemantics and StarlarkSemanticsOptions.
9730ce6 to
73ff880
Compare
…behaviour if true The previous (pre PR) change has been re-added, and is used by default.
This allows to test with different values of the incompatible flag
73ff880 to
fafa256
Compare
|
|
||
| StarlarkSemantics semantics = thread.getSemantics(); | ||
| if (semantics.incompatibleStringReplaceCount()) { | ||
| if (count != Starlark.NONE && (Integer) count >= 0) { |
There was a problem hiding this comment.
Also: 'None' is not a legal argument for count, according to the Starlark spec (which matches Pythons 2 and 3 and go.starlark.net implementation).
There was a problem hiding this comment.
Hm, I'll write a quick followup to change the default value to the internal UNBOUND sentinel and have the incompatible flag also reject the value None.
There was a problem hiding this comment.
Thanks. I suggest to:
- Change the default value to unbound
- Raise an error if the argument is None and the incompatible flag is enabled
- After the flag flip, remove noneable=True
|
FYI in the internal merge we retained some of the test cases in |
Also update the name of the argument to be "count" instead of "maxsplit",
to match the Starlark spec.
This fixes #9181