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] add type hints on empty initializations #5445

Merged
merged 1 commit into from
Aug 30, 2022

Conversation

jameslamb
Copy link
Collaborator

Contributes to #3867.
Contributes to #3756.

mypy currently raises the following errors.

python-package/lightgbm/basic.py:2515: error: Need type annotation for "ref_chain" (hint: "ref_chain: Set[<type>] = ...")
python-package/lightgbm/basic.py:2734: error: Need type annotation for "valid_sets" (hint: "valid_sets: List[<type>] = ...")
python-package/lightgbm/basic.py:2735: error: Need type annotation for "name_valid_sets" (hint: "name_valid_sets: List[<type>] = ...")
python-package/lightgbm/engine.py:303: error: Need type annotation for "boosters" (hint: "boosters: List[<type>] = ...")

These come from places where an empty container is initialized, then later filled with values. Like this:

self.boosters = []

def _append(self, booster: Booster) -> None:
"""Add a booster to CVBooster."""
self.boosters.append(booster)

This PR adds type hints to fix those errors.

Notes for Reviewers

I tested this by running mypy as documented in #3867.

mypy \
    --exclude='python-package/compile/|python-package/build' \
    --ignore-missing-imports \
    python-package/

@jameslamb jameslamb merged commit 71b6550 into master Aug 30, 2022
@jameslamb jameslamb deleted the more-hints branch August 30, 2022 01:11
@jameslamb jameslamb mentioned this pull request Oct 7, 2022
40 tasks
@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 19, 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