Skip to content

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

Merged
jameslamb merged 1 commit into
masterfrom
ci/more-linting
Aug 19, 2023
Merged

jameslamb merged 1 commit into
masterfrom
ci/more-linting

Conversation

@jameslamb

Copy link
Copy Markdown
Member

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
@jameslamb
jameslamb deleted the ci/more-linting branch August 19, 2023 12:01
@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/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.

2 participants