Created
March 15, 2016 16:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| safe_division(1, 0, True, False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def safe_division_b(number, divisor, | |
| ignore_overflow=False, | |
| ignore_zero_division=False): | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| safe_division_b(1, 10**500, ignore_overflow=True) | |
| safe_division_b(1, 0, ignore_zero_division=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| safe_division_b(1, 0, True, False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def safe_division_c(number, divisor, *, | |
| ignore_overflow=False, | |
| ignore_zero_division=False): | |
| pass | |
| safe_division_c(1, 10**500, True, False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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