Created
January 28, 2018 06:14
-
-
Save rezkam/c4da31cefc05b8a63e5011d12e7967df to your computer and use it in GitHub Desktop.
decorator
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
from functools import wraps | |
def simple_decorator(func): | |
def __wrapper(*args, **kwargs): | |
return func(*args, **kwargs) | |
return __wrapper | |
def with_wraps(func): | |
@wraps(func) | |
def __wrapper(*args, **kwargs): | |
return func(*args, **kwargs) | |
return __wrapper | |
@simple_decorator | |
def simple(): | |
"""Here is simple doc string text.""" | |
pass | |
@with_wraps | |
def wrapper(): | |
"""Here is wrapper doc string text.""" | |
pass | |
# without using @wraps decorator | |
print simple.__doc__ | |
#>>> None | |
print simple.__name__ | |
#>>> __wrapper | |
# using @wraps decorator | |
print wrapper.__doc__ | |
#>>> Here is wrapper doc string text. | |
print wrapper.__name__ | |
#>>> wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment