Repository navigation
Convert type[Self] to callable from class constructor - #5592
Open
crypt0lith wants to merge 1 commit into
Open
crypt0lith wants to merge 1 commit into
crypt0lith wants to merge 1 commit into
Conversation
Converting type[Self], such as 'cls' in a classmethod, to a callable fell back to 'type.__call__', '(*args: Any, **kwds: Any) -> Any'. Passing 'cls' to a ParamSpec-generic function lost its signature, and assigning it to an incompatible callable type was allowed. Convert type[Self] from the constructor of the class bound to Self. As in a call through type[Self], change a constructor return that is an instance of the class to Self, so the converted callable still returns the subclass when the classmethod is inherited. Fixes meta#5591
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D130651720. (Because this pull request was imported automatically, there will not be any future comments.) |
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.
Summary
Converting
type[Self], such asclsin a classmethod, to a callable fell back totype.__call__,(*args: Any, **kwds: Any) -> Any. Passingclsto a ParamSpec-generic function lost its signature, and assigning it to an incompatible callable type was allowed.Convert
type[Self]from the constructor of the class bound toSelf. As in a call throughtype[Self], change a constructor return that is an instance of the class toSelf, so the converted callable still returns the subclass when the classmethod is inherited.Fixes #5591
Test Plan
cargo test -p pyrefly --lib test::constructors::test_type_of_self_as_callable