Created
August 21, 2020 21:36
-
-
Save amunchet/0b97cce559655509763499caeb6369c8 to your computer and use it in GitHub Desktop.
Unwrapping decorators in Python Function
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
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