Skip to content

Instantly share code, notes, and snippets.

@amunchet
Created August 21, 2020 21:36
Show Gist options
  • Save amunchet/0b97cce559655509763499caeb6369c8 to your computer and use it in GitHub Desktop.
Save amunchet/0b97cce559655509763499caeb6369c8 to your computer and use it in GitHub Desktop.
Unwrapping decorators in Python Function
def unwrap(f):
"""
Unwraps the function down to the last layer of __wrapped__
"""
found = False
b = f
count = 0
while not found:
try:
b = b.__wrapped__
count += 1
except AttributeError:
found = True
if count == 0:
raise Exception("Unwrapped Exception Found.") # To ensure proper testing for Jupiter
return b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment