Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- #922 Classify autoimport project sources by path containment (@marlon-costa-dc)
- #926, #929 Raise RefactoringError instead of IndexError/ModuleSyntaxError when extracting an empty or whitespace-only region (@aliassar)
- #933 Add type annotations to project.py (@lieryan)
- #919 Type `saveit` so decorated members keep their return type (@marlon-costa-dc)
- #119, #928 Fix IndexError in rename and find occurrences when a `from` import is the last thing in a module without a trailing newline (@mcepl)
- #921 Patch the else suite of try statements that also have a finally (@marlon-costa-dc)
- #937 Preserve non-ASCII argument expressions and default values when changing function signatures (@Jinyong-Li)
Expand Down
11 changes: 9 additions & 2 deletions rope/base/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import sys
import warnings
from typing import Callable, Concatenate, ParamSpec, TypeVar

_Self = TypeVar("_Self")
_Params = ParamSpec("_Params")
_Result = TypeVar("_Result")

def saveit(func):

def saveit(
func: Callable[Concatenate[_Self, _Params], _Result],
) -> Callable[Concatenate[_Self, _Params], _Result]:
"""A decorator that caches the return value of a function"""

name = "_" + func.__name__

def _wrapper(self, *args, **kwds):
def _wrapper(self: _Self, *args: _Params.args, **kwds: _Params.kwargs) -> _Result:
if not hasattr(self, name):
setattr(self, name, func(self, *args, **kwds))
return getattr(self, name)
Expand Down
Loading