Skip to content

Instantly share code, notes, and snippets.

@giwa
Created March 15, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giwa/29f03a40a34cd7d5bb3b to your computer and use it in GitHub Desktop.
Save giwa/29f03a40a34cd7d5bb3b to your computer and use it in GitHub Desktop.
EP 21 Enforce Clarity with Keyword-Only Arguments ref: http://qiita.com/giwa/items/7b04ce6f7262c2003321
def safe_division(number, divisor, ignore_overflow, ignore_zero_division):
try:
return number / divisor
except OverflowError:
if ignore_overflow:
return 0
else:
raise
except ZeroDivisionError:
if ignore_zero_division:
return float('inf')
else:
raise
safe_division(1, 0, True, False)
def safe_division_b(number, divisor,
ignore_overflow=False,
ignore_zero_division=False):
pass
safe_division_b(1, 10**500, ignore_overflow=True)
safe_division_b(1, 0, ignore_zero_division=True)
safe_division_b(1, 0, True, False)
def safe_division_c(number, divisor, *,
ignore_overflow=False,
ignore_zero_division=False):
pass
safe_division_c(1, 10**500, True, False)
safe_division_c(1, 10 **500, True, False)
TypeError: safe_division_c() takes 2 positional arguments but 4 were given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment