Skip to content
Snippets Groups Projects
Commit c46885c4 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fixes

parent 73c62d3d
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ def exhaust(iterator: tp.Iterator):
try:
while True:
next(iterator)
except (GeneratorExit, StopIteration):
except StopIteration:
pass
......@@ -42,7 +42,7 @@ class SelfClosingGenerator:
def __next__(self):
try:
return next(self.generator)
except (StopIteration, GeneratorExit):
except StopIteration:
self.stopped = True
raise
......@@ -51,15 +51,11 @@ class SelfClosingGenerator:
try:
exhaust(self.generator)
except TypeError:
pass
pass # we got a generator-generating function as an argument
self.stopped = True
raise GeneratorExit()
def __del__(self):
try:
self.close()
except GeneratorExit:
pass
self.close()
# noinspection PyPep8Naming
......
......@@ -22,8 +22,8 @@ class TestIterators(unittest.TestCase):
yield i
a['done'] = True
for i in SelfClosingGenerator(generator)():
if i == 2:
for a in SelfClosingGenerator(generator)():
if a == 2:
break
self.assertTrue(a['done'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment