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

[dask] fix typehint on _pad_eval_names() #4413

Merged
merged 1 commit into from
Jun 28, 2021
Merged

Conversation

jameslamb
Copy link
Collaborator

Following up on #4101 (review) (cc @ffineis just so you know this is what I was talking about in that comment).

The function lightgbm.dask._pad_eval_names() currently has a type hint suggesting that argument required_names could be None, but its code doesn't handle that case. The for loop below would fail with an error complaining about NoneType not being iterable.

for eval_name in required_names:

I don't think it is actually possible for that argument to ever be None, because of

if eval_names:
evals_result_name = eval_names[i]
else:
evals_result_name = f'valid_{i}'

model = _pad_eval_names(model, required_names=evals_result_names)

This PR proposes updating the type hint.

Notes for Reviewers

Noting that in the future, this is the type of thing that will be caught by mypy (#3867). Running mypy --ignore-missing-import python-package/lightgbm yields the following.

python-package/lightgbm/dask.py:98: error: Item "None" of "Optional[List[str]]" has no attribute "iter" (not iterable)

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye!

@StrikerRUS StrikerRUS merged commit b918b5b into master Jun 28, 2021
@StrikerRUS StrikerRUS deleted the fix/dask-typehint branch June 28, 2021 11:36
@ffineis
Copy link
Contributor

ffineis commented Jun 28, 2021

Slick, thanks very much for the fix.

@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 23, 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.

3 participants