Fix usages of contextmanager without finally (#96170)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/96170
Approved by: https://github.com/ngimel, https://github.com/malfet
This commit is contained in:
Horace He
2023-03-07 23:27:01 +00:00
committed by PyTorch MergeBot
parent 34d18c8bee
commit 5bbec680d7
15 changed files with 91 additions and 59 deletions

View File

@ -56,8 +56,10 @@ class SourceChangeWarning(Warning):
@contextmanager
def mkdtemp():
path = tempfile.mkdtemp()
yield path
shutil.rmtree(path)
try:
yield path
finally:
shutil.rmtree(path)
_package_registry = []