Created
November 21, 2016 03:18
-
-
Save wchargin/dae3cd75c337f9680df83c06a357acf4 to your computer and use it in GitHub Desktop.
This file contains 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
import traceback | |
def fn(): | |
if "psst" not in "".join(traceback.format_stack()[:-1]): | |
raise ValueError("hey go away") | |
def call_with_comment(): | |
fn() # psst let me in | |
def call_without_comment(): | |
fn() | |
def does_raise(target): | |
try: | |
target() | |
return False | |
except Exception: | |
return True | |
if __name__ == '__main__': | |
print does_raise(call_with_comment) # False | |
print does_raise(call_without_comment) # True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is horrifying. Nice illustration.
(I came here from the comment on Code Golf.)