Skip to content
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

[python-package] ignore some mypy errors in _DaskLGBMModel #5774

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

jameslamb
Copy link
Collaborator

Contributes to #3867.

Resolves the following mypy errors.

python-package/lightgbm/dask.py:1037: error: "_DaskLGBMModel" has no attribute "_other_params"  [attr-defined]
python-package/lightgbm/dask.py:1066: error: "_DaskLGBMModel" has no attribute "get_params"  [attr-defined]
python-package/lightgbm/dask.py:1089: error: "_DaskLGBMModel" has no attribute "set_params"  [attr-defined]
python-package/lightgbm/dask.py:1095: error: "_DaskLGBMModel" has no attribute "get_params"  [attr-defined]
python-package/lightgbm/dask.py:1104: error: Item "_DaskLGBMModel" of "Union[_DaskLGBMModel, LGBMModel]" has no attribute "get_params"  [union-attr]

Those errors all come from the fact that _DaskLGBMModel is used as a mixin alongside lightgbm.sklearn.LGBMModel...

class DaskLGBMClassifier(LGBMClassifier, _DaskLGBMModel):

... and references methods and attributes that it expects to come from lightgbm.sklearn.LGBMModel

self._lgb_dask_copy_extra_params(self, model)

There is in theory a way to handle this situation with typing.Protocol (https://mypy.readthedocs.io/en/stable/more_types.html#mixin-classes), but I couldn't figure it out tonight. So for now, given that these methods are all covered well by the many unit tests, this PR proposes just ignoring these errors from mypy.

@jameslamb
Copy link
Collaborator Author

thanks for the reviews on all these @jmoralez ! I swear we're getting closer to having everything type-annotated and fully enabling mypy 😅

@jameslamb jameslamb merged commit ac3668f into master Mar 15, 2023
@jameslamb jameslamb deleted the ci/mypy-dask-mixin-attrs branch March 15, 2023 03:36
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants