From time to time in Python, I see the block:
try: try_this(whatever) except SomeException as exception: #Handle exception else: return something >
Whenever you see this:
try: y = 1 / x except ZeroDivisionError: pass else: return y
Or even this:
try: return 1 / x except ZeroDivisionError: return None
Consider this instead:
import contextlib with contextlib.suppress(ZeroDivisionError): return 1 / x