danielfm / pybreaker

Python implementation of the Circuit Breaker pattern.
BSD 3-Clause "New" or "Revised" License
508 stars 74 forks source link

Replace raise with return per PEP 479 recommendations #46

Closed mnguyenngo closed 5 years ago

mnguyenngo commented 5 years ago

According to PEP 479 documentation (https://www.python.org/dev/peps/pep-0479/#examples-of-breakage), when StopIteration occurs, the generator should end with a return statement instead of a raise.

See the following example from PEP 479:

More complicated iteration patterns will need explicit try/except constructs. For example, a hypothetical parser like this:

def parser(f):
while True:
data = next(f)
while True:
line = next(f)
if line == "- end -": break
data += line
yield data

would need to be rewritten as:

def parser(f):
while True:
try:
data = next(f)
while True:
line = next(f)
if line == "- end -": break
data += line
yield data
except StopIteration:
return
danielfm commented 5 years ago

Hi! Sorry for the long delay.

Thanks for your contribution! :smile:

mnguyenngo commented 5 years ago

thanks @danielfm!