Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created November 21, 2016 03:18
Show Gist options
  • Save wchargin/dae3cd75c337f9680df83c06a357acf4 to your computer and use it in GitHub Desktop.
Save wchargin/dae3cd75c337f9680df83c06a357acf4 to your computer and use it in GitHub Desktop.
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
@mikeweilgart
Copy link

This is horrifying. Nice illustration.

(I came here from the comment on Code Golf.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment