Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-102828: emit deprecation warning for onerror arg to shutil.rmtree #102850

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

Merged
merged 3 commits into from
Mar 21, 2023

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Mar 20, 2023

I've asked on discord and was told that we normally emit the deprecation warning as soon as something is deprecated.

Lib/shutil.py Outdated
@@ -692,6 +693,11 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
onerror is deprecated and only remains for backwards compatibility.
If both onerror and onexc are set, onerror is ignored and onexc is used.
"""

if onerror is not None:
warnings.warn("onerror is deprecated, use onexc instead",
Copy link
Contributor

@giampaolo giampaolo Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rephrase this as "onerror argument is deprecated, use onexc instead" (emphasys on the fact that onerror is an argument)

@iritkatriel iritkatriel merged commit 7f760c2 into python:main Mar 21, 2023
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
@iritkatriel iritkatriel deleted the deprecationwarning branch April 3, 2023 17:42
@@ -692,6 +693,11 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
onerror is deprecated and only remains for backwards compatibility.
If both onerror and onexc are set, onerror is ignored and onexc is used.
"""

if onerror is not None:
warnings.warn("onerror argument is deprecated, use onexc instead",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warn call needs stacklevel=2 parameter so that the warning message shows what is making the deprecated call. Werkzeug's tests started failing on the latest 3.12 alpha because of this, and it's really hard to tell what's causing it (I think it's pytest) because the warning just points at this line right now instead of the caller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will fix.

iritkatriel added a commit to iritkatriel/cpython that referenced this pull request Apr 10, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants