-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Conversation
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", |
There was a problem hiding this comment.
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)
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will fix.
I've asked on discord and was told that we normally emit the deprecation warning as soon as something is deprecated.