-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
TYP: Typing fixes and improvements related to scipy.sparse
#62218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+34
−23
Conversation
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
The CI failure seems unrelated
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.
The promised sequel of #62211.
With this, all scipy-related squigglies that show up when
scipy-stubs
is installed, are fixed. There's still one issue that remains incore.missing
that's not related to scipy, but rather to (the lack of) a mypy--allow-redefinition
(or--allow-redefinition-new
) flag.The
scipy.sparse.spmatrix
magic that you're seeing works around the fact that thespmatrix
class has a very limited set of methods and attributes. For example, it has notocsc()
method, so it's invalid to dodata.tocsc()
.The
Protocol
that I've replaced it with here, can be thought of as the proposition "someT
s.t.T.shape: tuple[int, int]
andT.tocsc() -> csc_{array,matrix}". This *structural* type (i.e. the protocol) avoids having to write out the union of all 7
{}_matrix*nominal* types. I also took the liberty of sneaking in some unofficial support for the (non-legacy)
scipy.sparse._arraytypes, which in this case are compatible with the legacy
_matrix` types (in the duck-typing sense). I understand if that's considered out-of-scope here, and wouldn't mind reverting in that case.doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.