-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
need to preserve original functions docstring (#593)
- Loading branch information
1 parent
09ecdb8
commit 13f3fda
Showing
2 changed files
with
9 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from functools import wraps | ||
|
||
|
||
def forbid_offline(func): | ||
""" | ||
Custom decorator to forbid method interact with remote service in offline mode. | ||
Returns: | ||
""" | ||
|
||
@wraps(func) # uses functools.wraps to preserve the original function's metadata. | ||
def wrapper(self, *args, **kwargs): | ||
if self.client.offline: | ||
raise ValueError("Service is not available in offline mode.") | ||
return func(self, *args, **kwargs) | ||
|
||
# important! Custom decorator needs to preserve the original function's docstring | ||
wrapper.__doc__ = func.__doc__ | ||
|
||
return wrapper |