Fix "generator doesn't stop" on Windows

When TemporaryDirectory() cleans up on __exit__ it sometimes throws
OSError noting that the dir isn't empty. This happens after the
first yield in this generator and leads to the exception being handled
which leads to a second yield.

contextlib.contextmanager() fails then since the function it wraps is only
allowed to yield once.

Fix this by not yielding again in the error case.

Fixes #7947
This commit is contained in:
Christoph Reiter 2020-11-08 13:59:28 +01:00 committed by Jussi Pakkanen
parent 3e6fbde94c
commit 5dd174c60b
1 changed files with 1 additions and 1 deletions

View File

@ -785,7 +785,7 @@ class Compiler(metaclass=abc.ABCMeta):
# On Windows antivirus programs and the like hold on to files so # On Windows antivirus programs and the like hold on to files so
# they can't be deleted. There's not much to do in this case. Also, # they can't be deleted. There's not much to do in this case. Also,
# catch OSError because the directory is then no longer empty. # catch OSError because the directory is then no longer empty.
yield None return
@contextlib.contextmanager @contextlib.contextmanager
def cached_compile(self, code: str, cdata: coredata.CoreData, *, def cached_compile(self, code: str, cdata: coredata.CoreData, *,