Repository navigation
Type saveit so decorated members keep their return type - #919
Open
marlon-costa-dc wants to merge 5 commits into
Open
marlon-costa-dc wants to merge 5 commits into
marlon-costa-dc wants to merge 5 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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. |
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
saveitreturns an untyped wrapper, so type checkers see members it decorates, such asProject.pycore, as plain functions, and callers need a cast to use the result as aPyCore.This annotates
saveitwithParamSpecandConcatenate(intypingsince 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.pycoreassigned toPyCorewithout a cast: 0 errors), and the test suite passes locally on Python 3.10, 3.11, 3.13 and 3.14.