-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
strings, bytes: deprecate Title #48367
Comments
Not sure deprecation would do much. It's already got a big BUG annotation in the comment, and we can't get rid of it for compatibility reasons. But] pointing people to an actual bug-free replacement would be valuable. |
@robpike The reason for deprecation is three-fold:
|
It seems OK to turn the BUG note into something tooling will expose more directly. |
This proposal has been added to the active column of the proposals project |
Is this for tools to be aware that a bug exists, or to provide some suggested action around it? If the suggested action is to replace the code with something else, I think deprecation notices already fulfill that purpose. |
By "It seems OK to turn the BUG note into something tooling will expose more directly." |
Based on the discussion above, this proposal seems like a likely accept. |
I‘m perfectly happy with using Title for cases where I know and control the source strings, e.g. for translating member variable visibility. Cases would be overkill for these scenarios. I also wouldn‘t want the linter complain about me doing that. |
So in this case, you
In the event that all three of these are true, I don't see the issue with using Even if it weren't marked deprecated, users should still be made aware that there's a more robust/correct alternative for case mapping. And in that case, the situation wouldn't be much better than a linter warning.
True, but func exported(s string) string {
r, size := utf8.DecodeRuneInString(s)
return string(unicode.ToTitle(r)) + s[size:]
} |
My point is that there are perfectly valid uses of |
I'm curious about the perfectly valid use cases of Also, if your linter were to suddenly warn you on And if needed, you could scope a lint directive to a function or file, and declare your own func Title(s string) string {
//lint:ignore SA1019 I know what I'm doing
return strings.Title(s)
} Would this resolve the issue with adding a linter directive all over the place? |
No change in consensus, so accepted. 🎉 |
But what is the actual proposal being accepted? There is shift in thinking through the comments. |
@robpike Correct me if I'm wrong, but I think the accepted proposal is still what is written in the first comment. @andig's sentiment is to not have the linter flagging cases he knows to be correct. I presented the option to tell the linter to ignore these cases, without sprinkling the comment all over the codebase. |
I withdraw my objection. Searching around the Go codebase it seems this is the only occurrence of the BUG used in such a way (I was suspecting more). For my personal preference, BUG is explicit enough to not need more tooling support. If we stick to the compatibility guarantee then I also wouldn't want my legacy code being flagged or my CI broken- toolchain is more than just the compiler. The same would be true though for deprecation notices so it's a weak argument. That being said if you want to close the discussion due to having been accepted that's fine. One takeaway though- and that resonates with the new developer survey- It would help to better educate people on the ecosystem and available libraries (however that could be achieved). |
Reading through the comments again, I think the accepted proposal is actually to replace the Before: // Title returns a copy of the string s with all Unicode letters that begin words
// mapped to their Unicode title case.
//
// BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly. After: // Title returns a copy of the string s with all Unicode letters that begin words
// mapped to their Unicode title case.
//
// Deprecated: The rule Title uses for word boundaries does not handle Unicode
// punctuation properly. Use golang.org/x/text/cases instead. Edit: I sent in CL 359485. I think it can still use some wordsmithing. |
Change https://golang.org/cl/359485 mentions this issue: |
Although I fully understand the reason for this deprecation, I am not convinced that the message is clear and that the alternative is enough and worth the many extra bytes. I think we should specify in Go 1.18.1 that And I would like it to be deprecated removed because tools like Jetbrains' Goland keep reporting problems where the problems aren't actually there (using ASCII characters). Plus, Example: |
It's true that |
I think some of the users of
As mentioned in #51956 (comment), pass the Edit: I can see the argument that we clarify in the deprecated message how specifically people can use the |
Thanks for the answers. But I am still of the opinion (like @robpike after all, if I'm not wrong) that the deprecation must be removed and it should be specified that it is not good for Unicode. |
@frederikhors Let me put it this way. We made a decision here: add a deprecation notice to I do think that we should add an example for |
This was removed by Go upstream: golang/go#48367 Signed-off-by: Brandon Mitchell <[email protected]>
This was removed by Go upstream: golang/go#48367 Signed-off-by: Brandon Mitchell <[email protected]>
`strings.Title` has been deprecated starting in go 1.18. We haven't moved to this version yet, but we will need to at some point in the near future. To avoid issues when that time comes, this updates the few instances we had of this to start using the recommended replacement of `cases.Title`. golang/go#48367 https://tip.golang.org/doc/go1.18#minor_library_changes Signed-off-by: Sean McGinnis <[email protected]>
`strings.Title` has been deprecated starting in go 1.18. We haven't moved to this version yet, but we will need to at some point in the near future. To avoid issues when that time comes, this updates the few instances we had of this to start using the recommended replacement of `cases.Title`. golang/go#48367 https://tip.golang.org/doc/go1.18#minor_library_changes Signed-off-by: Sean McGinnis <[email protected]>
…7048) Signed-off-by: wujunwei <[email protected]> <!-- Thanks for sending a pull request! Before submitting: 1. Read our CONTRIBUTING.md guide 2. Name your PR as `<Feature Area>: Describe your change`. a. Do not end the title with punctuation. It will be added in the changelog. b. Start with an imperative verb. Example: Fix the latency between System A and System B. c. Use sentence case, not title case. d. Use a complete phrase or sentence. The PR title will appear in a changelog, so help other people understand what your change will be. 3. Rebase your PR if it gets out of sync with main --> **What this PR does / why we need it**: [Golang 1.18 deprecates the `strings.title function`](golang/go#48367) use `cases.Title(language.Und, cases.NoLower).String()` instead. **Which issue(s) this PR fixes**: **Special notes for your reviewer**: <!-- Note about CHANGELOG entries, if a change adds: * an important feature * fixes an issue present in a previous release, * causes a change in operation that would be useful for an operator of Loki to know then please add a CHANGELOG entry. For documentation changes, build changes, simple fixes etc please skip this step. We are attempting to curate a changelog of the most relevant and important changes to be easier to ingest by end users of Loki. Note about the upgrade guide, if this changes: * default configuration values * metric names or label names * changes existing log lines such as the metrics.go query output line * configuration parameters * anything to do with any API * any other change that would require special attention or extra steps to upgrade Please document clearly what changed AND what needs to be done in the upgrade guide. --> **Checklist** - [ ] Documentation added - [ ] Tests updated - [ ] Is this an important fix or new feature? Add an entry in the `CHANGELOG.md`. - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` Signed-off-by: wujw39640 <[email protected]>
…rafana#7048) Signed-off-by: wujunwei <[email protected]> <!-- Thanks for sending a pull request! Before submitting: 1. Read our CONTRIBUTING.md guide 2. Name your PR as `<Feature Area>: Describe your change`. a. Do not end the title with punctuation. It will be added in the changelog. b. Start with an imperative verb. Example: Fix the latency between System A and System B. c. Use sentence case, not title case. d. Use a complete phrase or sentence. The PR title will appear in a changelog, so help other people understand what your change will be. 3. Rebase your PR if it gets out of sync with main --> **What this PR does / why we need it**: [Golang 1.18 deprecates the `strings.title function`](golang/go#48367) use `cases.Title(language.Und, cases.NoLower).String()` instead. **Which issue(s) this PR fixes**: **Special notes for your reviewer**: <!-- Note about CHANGELOG entries, if a change adds: * an important feature * fixes an issue present in a previous release, * causes a change in operation that would be useful for an operator of Loki to know then please add a CHANGELOG entry. For documentation changes, build changes, simple fixes etc please skip this step. We are attempting to curate a changelog of the most relevant and important changes to be easier to ingest by end users of Loki. Note about the upgrade guide, if this changes: * default configuration values * metric names or label names * changes existing log lines such as the metrics.go query output line * configuration parameters * anything to do with any API * any other change that would require special attention or extra steps to upgrade Please document clearly what changed AND what needs to be done in the upgrade guide. --> **Checklist** - [ ] Documentation added - [ ] Tests updated - [ ] Is this an important fix or new feature? Add an entry in the `CHANGELOG.md`. - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` Signed-off-by: wujw39640 <[email protected]>
`strings.Title` is deprecated as of golang 1.18[1], and suggest to use `golang.org/x/text/cases` instead. [1] golang/go#48367 Signed-off-by: Dave Chen <[email protected]>
Packages
bytes
andstrings
define the methodTitle
:A known bug with this function is that it doesn't handle unicode punctuation properly (see #6801). However, this can't be addressed due to the backwards compatibility guarantee, since it would change the function's output. This means that issues like #34994 and #48356 can't be addressed, which want Title to work around punctuation and emoji.
Furthermore,
Title
doesn't take into account language-specific capitalization rules. For example, the Dutch word"ijsland"
should be capitalized as"IJsland"
, butTitle
returns"Ijsland"
.A more robust alternative is
golang.org/x/text/cases
. Callingcases.Title(<language>).Bytes(<bytes>)
orcases.Title(<language>).String(<string>)
will deal with punctuation, different languages, and capitalize phrases.Therefore, I propose deprecating
bytes.Title
andstrings.Title
in favor ofgolang.org/x/text/cases
.The text was updated successfully, but these errors were encountered: