Skip to content

Conversation

jorenham
Copy link
Contributor

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 in core.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 the spmatrix class has a very limited set of methods and attributes. For example, it has no tocsc() method, so it's invalid to dodata.tocsc().
The Protocol that I've replaced it with here, can be thought of as the proposition "some T s.t. T.shape: tuple[int, int] and T.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.


  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@jorenham
Copy link
Contributor Author

The CI failure seems unrelated

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.

1 participant