Skip to content

[python-package] Fix mypy checks in compat.py - #6898

Merged
jameslamb merged 3 commits into
masterfrom
mypy-checks-compat
Jul 29, 2025
Merged

jameslamb merged 3 commits into
masterfrom
mypy-checks-compat

Conversation

@borchero

@borchero borchero commented Apr 27, 2025 •

Copy link
Copy Markdown
Member

Motivation

Contributes to #3867

mypy currently fails with 36 errors in 6 files. One of these files is compat.py.

Changes

This PR fixes the typing issues in compat.py, eliminating 2 errors in 1 file. I don't think there is a strong drawback in using Any here, this is a "stub function" anyways.

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this!

I'd like to see the specific warnings this is trying to address before approving this PR... maybe I'll be able to suggest something more specific than Any that we could use here. Can you please add them to the PR description in plaintext?

@jameslamb
jameslamb self-requested a review July 29, 2025 02:00

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to see the specific warnings this is trying to address before approving this PR

I want to move these forward so I just ran mypy myself to get this information. It's these:

python-package/lightgbm/compat.py:38: error: Function is missing a return type annotation  [no-untyped-def]
python-package/lightgbm/compat.py:38: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]

I think it's fine to just :Any these away. This function is just a compatibility layer for older version of scikit-learn that's uses internal to LightGBM... we have unit tests covering it, and having imprecise type hints does not affect the ability of other projects using LightGBM to use type-checkers on their own code that interacts with LightGBM.

I can see in the output of the lint job here (just run by me merging latest master into this PR) that there are no remaining compat.py errors from mypy on this branch: https://github.com/microsoft/LightGBM/actions/runs/16584600180/job/46907384257?pr=6898#step:3:991

I am ok with merging this.

@jameslamb
jameslamb merged commit 2a5e33b into master Jul 29, 2025
@jameslamb
jameslamb deleted the mypy-checks-compat branch July 29, 2025 03:22
@github-actions

Copy link
Copy Markdown
Contributor

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/lightgbm-org/LightGBM/issues including a reference to this.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants