Skip to content

Commit 6bf4c13

Browse files
Enable flake8-return in ruff (#10988)
flake8-return rule that flags a local variable assigned only to be returned on the next line.
1 parent b080a21 commit 6bf4c13

13 files changed

Lines changed: 19 additions & 26 deletions

File tree

pylint/checkers/format.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,10 @@ def check_line_length(self, line: str, i: int, checker_off: bool) -> None:
614614
def remove_pylint_option_from_lines(options_pattern_obj: Match[str]) -> str:
615615
"""Remove the `# pylint ...` pattern from lines."""
616616
lines = options_pattern_obj.string
617-
purged_lines = (
617+
return (
618618
lines[: options_pattern_obj.start(1)].rstrip()
619619
+ lines[options_pattern_obj.end(1) :]
620620
)
621-
return purged_lines
622621

623622
@staticmethod
624623
def is_line_length_check_activated(pylint_pattern_match_object: Match[str]) -> bool:

pylint/checkers/imports.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,14 +1022,12 @@ def _get_out_of_order_string(
10221022
)
10231023
delimiter_first_party2 = ("and " if local else "") if first_party else ""
10241024
delimiter_first_party = f"{delimiter_first_party1}{delimiter_first_party2}"
1025-
msg = (
1025+
return (
10261026
f"{third_party}{delimiter_third_party}"
10271027
f"{first_party}{delimiter_first_party}"
10281028
f'{local if local else ""}'
10291029
)
10301030

1031-
return msg
1032-
10331031
def _get_full_import_name(self, importNode: ImportNode) -> str:
10341032
# construct a more descriptive name of the import
10351033
# for: import X, this returns X

pylint/pyreverse/diadefslib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ def get_leaf_nodes(self) -> list[str]:
6464
6565
A leaf node is one that is not a prefix (with an extra dot) of any other node.
6666
"""
67-
leaf_nodes = [
67+
return [
6868
module
6969
for module in self.args
7070
if not any(
7171
other != module and other.startswith(module + ".")
7272
for other in self.args
7373
)
7474
]
75-
return leaf_nodes
7675

7776
def _set_option(self, option: bool | None) -> bool:
7877
"""Activate some options if not explicitly deactivated."""

pylint/pyreverse/dot_printer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ def _build_label_for_node(self, properties: NodeProperties) -> str:
143143
def _escape_annotation_label(self, annotation_label: str) -> str:
144144
# Escape vertical bar characters to make them appear as a literal characters
145145
# otherwise it gets treated as field separator of record-based nodes
146-
annotation_label = annotation_label.replace("|", r"\|")
147-
148-
return annotation_label
146+
return annotation_label.replace("|", r"\|")
149147

150148
def emit_edge(
151149
self,

pylint/pyreverse/mermaidjs_printer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def _open_graph(self) -> None:
3535

3636
def _escape_mermaid_text(self, text: str) -> str:
3737
"""Escape characters that conflict with Markdown formatting."""
38-
text = text.replace("__", r"\_\_") # Double underscore → escaped
39-
return text
38+
return text.replace("__", r"\_\_") # Double underscore → escaped
4039

4140
def emit_node(
4241
self,

pylint/pyreverse/writer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,13 @@ def get_package_properties(self, obj: PackageEntity) -> NodeProperties:
185185

186186
def get_class_properties(self, obj: ClassEntity) -> NodeProperties:
187187
"""Get label and shape for classes."""
188-
properties = NodeProperties(
188+
return NodeProperties(
189189
label=obj.title,
190190
attrs=obj.attrs if not self.config.only_classnames else None,
191191
methods=obj.methods if not self.config.only_classnames else None,
192192
fontcolor="red" if is_exception(obj.node) else "black",
193193
color=self.get_shape_color(obj) if self.config.colorized else "black",
194194
)
195-
return properties
196195

197196
def get_shape_color(self, obj: DiagramEntity) -> str:
198197
"""Get shape color."""

pylint/testutils/configuration_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,4 @@ def run_using_a_configuration_file(
151151
# in `_msg_states`, used by `is_message_enabled`.
152152
check = "pylint.lint.pylinter.check_parallel"
153153
with unittest.mock.patch(check):
154-
runner = Run(args, exit=False)
155-
return runner
154+
return Run(args, exit=False)

pylint/utils/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def cmp(a: float, b: float) -> int:
8484
def diff_string(old: float, new: float) -> str:
8585
"""Given an old and new value, return a string representing the difference."""
8686
diff = abs(old - new)
87-
diff_str = f"{CMPS[cmp(old, new)]}{(diff and f'{diff:.2f}') or ''}"
88-
return diff_str
87+
return f"{CMPS[cmp(old, new)]}{(diff and f'{diff:.2f}') or ''}"
8988

9089

9190
def get_module_and_frameid(node: nodes.NodeNG) -> tuple[str, str]:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ lint.select = [
128128
"PIE", # flake8-pie
129129
"PTH", # flake8-pathlib
130130
"PYI", # flake8-pyi
131+
"RET", # flake8-return
131132
"RUF", # ruff
132133
"UP", # pyupgrade
133134
"W", # pycodestyle

tests/pyreverse/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def _astroid_wrapper(
9292
return func(modname)
9393

9494
with augmented_sys_path([discover_package_path(module, [])]):
95-
project = project_from_files([module], _astroid_wrapper, project_name=name)
96-
return project
95+
return project_from_files([module], _astroid_wrapper, project_name=name)
9796

9897
return _get_project

0 commit comments

Comments
 (0)