-
Notifications
You must be signed in to change notification settings - Fork 164
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
Add removeprefix/removesuffix to string #185
Comments
Summary: These methods got added in Python 3.9. I've seen two engineers get this wrong without these utilities, so add them. I've also proposed their addition to Starlark in bazelbuild/starlark#185. Reviewed By: milend Differential Revision: D27077457 fbshipit-source-id: 6d1eb4a6b1c775fdfa1bcbf62f71809e1dcb44c1
Seems reasonable. I'm amazed they took until 3.9 to appear. |
@adonovan Given these are already in Rust Starlark, what would I need to do to add them to the spec + Bazel? Happy to work on PRs as I would find these functions very useful. |
Thanks for volunteering. Could you send a PR to change to the spec adjacent to https://github.com/bazelbuild/starlark/blob/master/spec.md#string%C2%B7endswith, which we can review? Once that's approved the maintainers of the various implementations can add the function, which should be very straightforward. I can do the Go one and @brandjon can do Java. |
I submitted #212 as an update to the spec and have prepared bazelbuild/bazel#14824 to implement it in Java Starlark. |
Implements bazelbuild/starlark#185 in Java Starlark. Closes #14824. PiperOrigin-RevId: 430556229
Implements bazelbuild/starlark#185 in Java Starlark. Closes bazelbuild#14824. PiperOrigin-RevId: 430556229
Implements bazelbuild/starlark#185 in Java Starlark. Closes #14824. PiperOrigin-RevId: 430556229
Someone wanted to change
libFoos.so
toFoos
so they did the (not unreasonable)x.lstrip("lib").rstrip(".so")
, which looks like it does that, but completely doesn't (it returnsFoo
). I then change that to index slicing, in particular[:-len(extension)]
, but that fails in the corner case of an empty extension. These aren't unreasonable things to do, but the default Starlark operators are full of pitfalls.Python 3.9 added
string.removeprefix
andstring.removesuffix
. I've added them to the Rust Starlark, since they are super helpful and avoid bugs. It would be great to add them to standard Starlark too.The text was updated successfully, but these errors were encountered: