Skip to content
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

proposal: io/ioutil: Annotate functions with "Deprecated: " #51927

Closed
jeffwidman opened this issue Mar 24, 2022 · 4 comments
Closed

proposal: io/ioutil: Annotate functions with "Deprecated: " #51927

jeffwidman opened this issue Mar 24, 2022 · 4 comments

Comments

@jeffwidman
Copy link
Contributor

jeffwidman commented Mar 24, 2022

go 1.16 deprecated io/ioutil.

However, the relevant code never got the "Deprecated: " marker: https://tip.golang.org/src/io/ioutil/ioutil.go

Is there are a reason for this?

We've found in our own source code that it's easy for someone to reuse a code snippet, forgetting that ioutil is deprecated, and accidentally introduce it again and again into our code base.

Today the only way to remember to not let this creep have to implement special checks which seems like a lot of extra effort compared to leveraging the built-in deprecated marker.

Now that 1.18 has dropped, and the core team no longer supports 1.16, would it be okay to mark these functions as deprecated starting with 1.19?

This way linters start reminding folks to move away from this code, and prevent new uses of it.

I'd be happy to submit a PR, but wanted to get approval in case there's a reason this hasn't been done yet.

Related: #45557

@jeffwidman jeffwidman changed the title proposal: io/ioutil: Mark as deprecated in the code proposal: io/ioutil: Annotate functions with "Deprecated: " Mar 24, 2022
@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Mar 24, 2022 via email

@jeffwidman
Copy link
Contributor Author

jeffwidman commented Mar 25, 2022

Sounds good. I nudged the author of #43799 and will give him a few days. If he's not interested or unreachable then I'll open a PR next week for this.

@gopherbot
Copy link

Change https://go.dev/cl/395918 mentions this issue: io/ioutil: add deprecation markers to ioutil

@gopherbot
Copy link

Change https://go.dev/cl/399854 mentions this issue: io/ioutil: provide an equivalent for the deprecated ReadDir

gopherbot pushed a commit that referenced this issue Apr 19, 2022
All APIs in the now-deprecated io/ioutil package have a direct
replacement in either the io or os package with the same signature,
with the notable exception of ioutil.ReadDir, as os.ReadDir has a
slightly different signature with fs.DirEntry rather than fs.FileInfo.

New code can easily make use of []fs.DirEntry directly,
but existing code may need to continue using []fs.FileInfo for backwards
compatibility reasons. For instance, I had a bit of code that exposed
the slice as a public API, like:

	return ioutil.ReadDir(name)

It took me a couple of minutes to figure out what the exact equivalent
in terms of os.ReadDir would be, and a code sample would have helped.
Add one for future reference.

For #42026.
For #51927.

Change-Id: I76d46cd7d68fc609c873821755fdcfc299ffd56c
Reviewed-on: https://go-review.googlesource.com/c/go/+/399854
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
@golang golang locked and limited conversation to collaborators Apr 12, 2023
@dmitshur dmitshur modified the milestones: Proposal, Go1.19 Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants