Unverified Commit 9111ade7 authored by Yusuke Horibe's avatar Yusuke Horibe Committed by GitHub
Browse files

[python-package] Add superfluous-else-raise (RET506) rule to Ruff (#6904)

* [python-package] Add superfluous-else-raise rule to ruff lint configuration

* [python-package] Fix code to follow superfluous-else-raise rule

* [python-package] Move RET506 after RET504 to maintain alphabetical order and add source rule set comment

* [python-package] Revert unintended change to preserve original formatting
parent ec5492f8
......@@ -254,7 +254,6 @@ def generate_doxygen_xml(app: Sphinx) -> None:
output = "\n".join([i.decode("utf-8") for i in (stdout, stderr) if i is not None])
if process.returncode != 0:
raise RuntimeError(output)
else:
print(output)
except BaseException as e:
raise Exception(f"An error has occurred while executing Doxygen\n{e}")
......@@ -303,7 +302,6 @@ def generate_r_docs(app: Sphinx) -> None:
output = "\n".join([i for i in (stdout, stderr) if i is not None])
if process.returncode != 0:
raise RuntimeError(output)
else:
print(output)
print("Done building R-package documentation")
except BaseException as e:
......
......@@ -1130,7 +1130,7 @@ class _InnerPredictor:
"""
if isinstance(data, Dataset):
raise TypeError("Cannot use Dataset instance for prediction, please use raw data instead")
elif isinstance(data, pd_DataFrame) and validate_features:
if isinstance(data, pd_DataFrame) and validate_features:
data_names = [str(x) for x in data.columns]
ptr_names = (ctypes.c_char_p * len(data_names))()
ptr_names[:] = [x.encode("utf-8") for x in data_names]
......@@ -5097,7 +5097,6 @@ class Booster:
if split_feature == feature:
if isinstance(root["threshold"], str):
raise LightGBMError("Cannot compute split value histogram for the categorical feature")
else:
values.append(root["threshold"])
add(root["left_child"])
add(root["right_child"])
......
......@@ -1761,9 +1761,9 @@ class LGBMRanker(LGBMModel):
if eval_set is not None:
if eval_group is None:
raise ValueError("Eval_group cannot be None when eval_set is not None")
elif len(eval_group) != len(eval_set):
if len(eval_group) != len(eval_set):
raise ValueError("Length of eval_group should be equal to eval_set")
elif (
if (
isinstance(eval_group, dict)
and any(i not in eval_group or eval_group[i] is None for i in range(len(eval_group)))
or isinstance(eval_group, list)
......
......@@ -157,6 +157,8 @@ select = [
"PL",
# flake8-return: unnecessary assignment before return
"RET504",
# flake8-return: superfluous-else-raise
"RET506",
# flake8-simplify: use dict.get() instead of an if-else block
"SIM401",
# flake8-print
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment