You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My proposal is to allow user-defined generics to infer the generic from their first usage, so that the example work.
Pitch
This problem arose in the context of making a typed library compatible with scikit-learn (which currently is not typed). In scikit-learn, the actual data of a machine learning problem is not passed to the constructor of the object, but instead passed to the fit method (for training). Thus, if one wants to make a scikit-learn compatible object which is generic over the data accepted, one currently needs to provide the annotation, as Mypy won't infer the generic type from the call to fit. This is cumbersome for users, as most of them should benefit from the typing without altering the code to add superfluous annotations. It also obscures the examples, as adding annotations would confuse users not used to them.
The text was updated successfully, but these errors were encountered:
Feature
Multi-statement inference as proposed in #254 and #1055 is supported for empty standard collection classes, like dict or list, but not for custom classes. Thus, an example such as https://mypy-play.net/?mypy=latest&python=3.10&gist=7df00fc3d8612804369dbad6b5cb973b fails.
My proposal is to allow user-defined generics to infer the generic from their first usage, so that the example work.
Pitch
This problem arose in the context of making a typed library compatible with scikit-learn (which currently is not typed). In scikit-learn, the actual data of a machine learning problem is not passed to the constructor of the object, but instead passed to the
fit
method (for training). Thus, if one wants to make a scikit-learn compatible object which is generic over the data accepted, one currently needs to provide the annotation, as Mypy won't infer the generic type from the call tofit
. This is cumbersome for users, as most of them should benefit from the typing without altering the code to add superfluous annotations. It also obscures the examples, as adding annotations would confuse users not used to them.The text was updated successfully, but these errors were encountered: