From 068eb96f72e3815b8c9bf28fb215b4f39da3c815 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Sat, 31 Oct 2026 16:23:23 -0300 Subject: [PATCH 1/2] Type saveit so decorated members keep their return type saveit returned an untyped wrapper, so type checkers saw members such as Project.pycore as a plain function and their callers needed casts. Annotate it with ParamSpec and Concatenate, available in typing since Python 3.10; the runtime behaviour is unchanged. (cherry picked from commit 658024247d3b85aaa72507ff7d0f23ff6b0d79de) Co-Authored-By: Claude Opus 5.5 --- rope/base/utils/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rope/base/utils/__init__.py b/rope/base/utils/__init__.py index c96c96428..bdd5da0a7 100644 --- a/rope/base/utils/__init__.py +++ b/rope/base/utils/__init__.py @@ -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) From 2a906ae755775fec21bd71b83a696e644b6f1773 Mon Sep 17 00:00:00 2001 From: Marlon Costa Date: Sat, 31 Oct 2026 16:27:31 -0300 Subject: [PATCH 2/2] Add changelog entry Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7ddf653..2461ce540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - #895 patchedast Starred and keyword now consumes their syntactically expected and ** (@lieryan) - #896 patchedast cleanup and refactoring (@lieryan) - #905 Ignore `node_modules` directories by default when scanning project files and source folders. (@marcoeangeli) +- #919 Type `saveit` so decorated members keep their return type (@marlon-costa-dc) # Release 1.15.0