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

[ci] [python-package] add more linting checks #6049

Merged
merged 1 commit into from Aug 19, 2023
Merged

Conversation

jameslamb
Copy link
Collaborator

Proposes adding a few more linting rules for Python code in this project, to further standardize how the code looks.

  • flake8-print: encourages the use of the configured logger over print() and pprint()
  • flake8-return (just one of the checks): avoid unnecessary assignment immediately before a return()
  • flake8-simplify (just one of the checks): use dict.get(key. default) instead of an if-else loop

This PR adds those checks to the project's linting config, and modifies the project's code to address these specific warnings:

python-package/lightgbm/basic.py:129:9: T201 `print` found
python-package/lightgbm/basic.py:474:16: RET504 [*] Unnecessary assignment to `aliases` before `return` statement
python-package/lightgbm/basic.py:3213:16: RET504 [*] Unnecessary assignment to `booster` before `return` statement
python-package/lightgbm/plotting.py:737:12: RET504 [*] Unnecessary assignment to `graph` before `return` statement
python-package/lightgbm/plotting.py:696:5: SIM401 [*] Use `feature_names = model.get('feature_names', None)` instead of an `if` block
tests/distributed/_test_distributed.py:28:12: RET504 [*] Unnecessary assignment to `port` before `return` statement
tests/distributed/_test_distributed.py:51:12: RET504 [*] Unnecessary assignment to `dataset` before `return` statement
tests/distributed/_test_distributed.py:153:16: RET504 [*] Unnecessary assignment to `y_pred` before `return` statement
tests/python_package_test/test_engine.py:1724:12: RET504 [*] Unnecessary assignment to `trainset` before `return` statement
tests/python_package_test/utils.py:195:12: RET504 [*] Unnecessary assignment to `obj_from_disk` before `return` statement

Docs for these checks can be found at https://beta.ruff.rs/docs/rules.

@jameslamb jameslamb merged commit c60bc73 into master Aug 19, 2023
41 checks passed
@jameslamb jameslamb deleted the ci/more-linting branch August 19, 2023 12:01
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 Nov 22, 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.

None yet

2 participants