Skip to content

Commit

Permalink
need to preserve original functions docstring (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
longshuicy authored Aug 29, 2024
1 parent 09ecdb8 commit 13f3fda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Fixed
- Fixed Sphinx autodoc skipping class methods with custom decorators. [#518](https://github.com/IN-CORE/pyincore/issues/518)
- Pyomo version fixed to fix indp solver failure [#585](https://github.com/IN-CORE/pyincore/issues/585)

### Changed
Expand Down
8 changes: 8 additions & 0 deletions pyincore/decorators.py
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

0 comments on commit 13f3fda

Please sign in to comment.