Skip to content

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

Merged
asottile merged 1 commit into
pre-commit:mainfrom
edgarrmondragon:deprecation-rmtree-onerror
Dec 9, 2023
Merged

Address deprecation warning in shutil.rmtree(onerror=...)#3079
asottile merged 1 commit into
pre-commit:mainfrom
edgarrmondragon:deprecation-rmtree-onerror

Conversation

@edgarrmondragon

Copy link
Copy Markdown
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

asottile commented Dec 1, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
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

asottile commented Dec 1, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@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.

2 participants