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
Since mypy passes the code to AST and that's how they check for types and available methods, any code using these methods such as est.set_fit_request(sample_weight=True) would make mypy to fail with and error similar to:
error: "LinearRegression" has no attribute "set_fit_request"
There are at least two ways to fix this issue:
Write a plugin for mypy to somehow fix the issues:
Declare all possible methods for all objects for type checkers even if they don't exist. This would silence the type checker errors, but it's a bit hackish. For this, we'd need to change the declaration of the _MetadataRequester and add:
set_{method}_request
methods are added to all estimators inheriting fromBaseEstimator
, around this part of the code:scikit-learn/sklearn/utils/_metadata_requests.py
Lines 1004 to 1013 in e9f5676
Since
mypy
passes the code to AST and that's how they check for types and available methods, any code using these methods such asest.set_fit_request(sample_weight=True)
would makemypy
to fail with and error similar to:There are at least two ways to fix this issue:
mypy
to somehow fix the issues:mypy
's reference: https://mypy.readthedocs.io/en/stable/extending_mypy.htmlnumpy
's example: https://numpy.org/devdocs/reference/typing.html_MetadataRequester
and add:This wouldn't pollute the runtime env since in runtime
TYPE_CHECKING
is alwaysFalse
.I'm in favor of adding the second option as a temporary solution until somebody implemented the plugin, if they do.
The text was updated successfully, but these errors were encountered: