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

Address deprecation warning in shutil.rmtree(onerror=...) #3079

Merged

Conversation

edgarrmondragon
Copy link
Contributor

shutil.rmtree() now accepts a new argument onexc which is an error handler like onerror but which expects an exception instance rather than a (typ, val, tb) triplet. onerror is deprecated and will be removed in Python 3.14. (Contributed by Irit Katriel in gh-102828.)

https://docs.python.org/3.12/whatsnew/3.12.html#shutil

@asottile
Copy link
Member

asottile commented Dec 1, 2023

cast should only be used for bugs in the type system

I don't think we need this function any more sooner than the deprecation matters so I'm probably going to decline this anyway

@edgarrmondragon
Copy link
Contributor Author

cast should only be used for bugs in the type system

I don't think we need this function any more sooner than the deprecation matters so I'm probably going to decline this anyway

No problem. And I prefer avoiding cast but Mypy was complaining that "tuple[type[OSError], OSError, TracebackType] | BaseException" is not indexable.

@asottile
Copy link
Member

asottile commented Dec 1, 2023

cast should only be used for bugs in the type system
I don't think we need this function any more sooner than the deprecation matters so I'm probably going to decline this anyway

No problem. And I prefer avoiding cast but Mypy was complaining that "tuple[type[OSError], OSError, TracebackType] | BaseException" is not indexable.

yeah it's not -- the way you've written it is not typesafe

@edgarrmondragon
Copy link
Contributor Author

FWIW I added a guard to check if the exception is an OSError so that allowed to remove the cast call.

@asottile asottile merged commit 23a2b73 into pre-commit:main Dec 9, 2023
44 checks passed
@edgarrmondragon edgarrmondragon deleted the deprecation-rmtree-onerror branch February 7, 2024 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants