Skip to content

Type saveit so decorated members keep their return type - #919

Open
marlon-costa-dc wants to merge 5 commits into
python-rope:masterfrom
marlon-costa-dc:pr/typed-saveit
Open

marlon-costa-dc wants to merge 5 commits into
python-rope:masterfrom
marlon-costa-dc:pr/typed-saveit

Conversation

@marlon-costa-dc

Copy link
Copy Markdown
Contributor

saveit returns an untyped wrapper, so type checkers see members it decorates, such as Project.pycore, as plain functions, and callers need a cast to use the result as a PyCore.

This annotates saveit with ParamSpec and Concatenate (in typing since Python 3.10, the minimum supported version), so the decorated member keeps its parameters and return type. The runtime behaviour is unchanged.

Checked with pyright on a consumer (project.pycore assigned to PyCore without a cast: 0 errors), and the test suite passes locally on Python 3.10, 3.11, 3.13 and 3.14.

marlon-costa-dc and others added 2 commits October 31, 2026 16:26
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 6580242)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.44%. Comparing base (ff8a306) to head (811eec2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #919   +/-   ##
=======================================
  Coverage   95.44%   95.44%           
=======================================
  Files         134      134           
  Lines       26910    26914    +4     
=======================================
+ Hits        25685    25689    +4     
  Misses       1225     1225           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lieryan

lieryan commented Nov 2, 2026

Copy link
Copy Markdown
Member

I'm not very familiar with the ParamSpec/Concatenate stuffs of the typing module, but this looks reasonable.

But for some time, I've been thinking of deprecating saveit and possibly looking to replacing them with the caching functions from stdlib functool.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants