Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT make type checkers happy with set_{method}_request methods #26911

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

Merged
merged 4 commits into from
Aug 1, 2023

Conversation

adrinjalali
Copy link
Member

This makes mypy (and other type checkers) happy by hard coding potentially generated methods to the parent class.

This code is never run in runtime, and is only there for type checkers since TYPE_CHECKING is False during runetime.

Right now, mypy would complain with the code:

from sklearn.linear_model import LogisticRegression

LogisticRegression().set_fit_request(sample_weight=True)

and say:

error: "LogisticRegression" has no attribute "set_fit_request"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

with this PR, the above errors are gone. It's still not idea, since we're telling mypy methods exist even if they don't, and we don't tell it about their signature.

cc @thomasjpfan @glemaitre @rth

@github-actions
Copy link

github-actions bot commented Jul 27, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 0e1968d. Link to the linter CI: here

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM

@glemaitre glemaitre merged commit ec41b3e into scikit-learn:main Aug 1, 2023
@glemaitre
Copy link
Member

Thanks @adrinjalali

@adrinjalali adrinjalali deleted the slep6/mypy branch August 1, 2023 10:44
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants