Skip to content

Commit bea720d

Browse files
committed
refactor: fix some flake8-return warnings
1 parent b2bff02 commit bea720d

33 files changed

+271
-267
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ select = [
272272
#"INP",
273273
"PIE",
274274
# "T20",
275-
"PT"
275+
"PT",
276+
"Q",
277+
"RET"
276278
]
277279

278280

robotcode/debugger/debugger.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ def set_breakpoints(
440440
Breakpoint(id=id(v), source=Source(path=str(path)), verified=True, line=v.line)
441441
for v in result.breakpoints
442442
]
443-
else:
444-
self._logger.error("not supported breakpoint")
443+
444+
self._logger.error("not supported breakpoint")
445445

446446
return []
447447

@@ -452,7 +452,7 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
452452
if self.state == State.Stopped:
453453
return
454454

455-
elif self.requested_state == RequestedState.Pause:
455+
if self.requested_state == RequestedState.Pause:
456456
self.state = State.Paused
457457
self.send_event(
458458
self,
@@ -555,18 +555,18 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
555555
),
556556
)
557557
return
558-
else:
559-
self.state = State.Paused
560-
self.send_event(
561-
self,
562-
StoppedEvent(
563-
body=StoppedEventBody(
564-
reason=StoppedReason.BREAKPOINT,
565-
thread_id=threading.current_thread().ident,
566-
hit_breakpoint_ids=[id(v) for v in breakpoints],
567-
)
568-
),
569-
)
558+
559+
self.state = State.Paused
560+
self.send_event(
561+
self,
562+
StoppedEvent(
563+
body=StoppedEventBody(
564+
reason=StoppedReason.BREAKPOINT,
565+
thread_id=threading.current_thread().ident,
566+
hit_breakpoint_ids=[id(v) for v in breakpoints],
567+
)
568+
),
569+
)
570570

571571
def process_end_state(self, status: str, filter_id: Set[str], description: str, text: Optional[str]) -> None:
572572
if (
@@ -940,8 +940,8 @@ def map_path_to_client(self, path: Union[os.PathLike[str], str]) -> pathlib.Pure
940940
):
941941
if self.is_windows_path(mapping.local_root):
942942
return pathlib.PureWindowsPath(mapping.local_root, relative_path)
943-
else:
944-
return pathlib.PurePath(mapping.local_root, relative_path)
943+
944+
return pathlib.PurePath(mapping.local_root, relative_path)
945945

946946
return path
947947

@@ -961,8 +961,8 @@ def get_stack_trace(
961961
def source_from_entry(entry: StackFrameEntry) -> Optional[Source]:
962962
if entry.source is not None and entry.is_file:
963963
return Source(path=str(self.map_path_to_client(entry.source)))
964-
else:
965-
return None
964+
965+
return None
966966

967967
def yield_stack() -> Iterator[StackFrame]:
968968
for i, v in enumerate(itertools.islice(self.stack_frames, start_frame, levels)):

robotcode/debugger/launcher/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ async def _disconnect(self, arguments: Optional[DisconnectArguments] = None, *ar
314314
@rpc_method(name="terminate", param_type=TerminateArguments)
315315
async def _terminate(self, arguments: Optional[TerminateArguments] = None, *args: Any, **kwargs: Any) -> None:
316316
if self.client.connected:
317-
return await self.client.protocol.send_request_async(TerminateRequest(arguments=arguments))
317+
await self.client.protocol.send_request_async(TerminateRequest(arguments=arguments))
318318
else:
319319
self.send_event(Event("terminateRequested"))
320320
await self.send_event_async(TerminatedEvent())

robotcode/debugger/protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _generate_json_rpc_messages_from_dict(
123123
def inner(d: Dict[Any, Any]) -> ProtocolMessage:
124124
result = from_dict(d, (Request, Response, Event))
125125
if isinstance(result, Response) and not result.success:
126-
result = from_dict(d, ErrorResponse)
126+
return from_dict(d, ErrorResponse)
127127
return result
128128

129129
if isinstance(data, list):
@@ -174,8 +174,8 @@ def _convert_params(
174174
if param_type is None:
175175
if isinstance(params, Mapping):
176176
return [], dict(**params)
177-
else:
178-
return [params], {}
177+
178+
return [params], {}
179179

180180
converted_params = from_dict(params, param_type)
181181

robotcode/jsonrpc2/protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ def _convert_params(
645645
if params_type is None:
646646
if isinstance(params, Mapping):
647647
return [], dict(**params)
648-
else:
649-
return [params], {}
648+
649+
return [params], {}
650650

651651
# try to convert the dict to correct type
652652
converted_params = from_dict(params, params_type)
@@ -701,7 +701,7 @@ async def handle_request(self, message: JsonRPCRequest) -> None:
701701
f"Unknown method: {message.method}",
702702
id=message.id,
703703
)
704-
return None
704+
return
705705

706706
params = self._convert_params(e.method, e.param_type, message.params)
707707

robotcode/language_server/common/parts/completion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ async def _text_document_completion(
116116
if len(result.items) == 0:
117117
return None
118118
return result
119-
else:
120-
result = list(chain(*[k for k in results if isinstance(k, list)]))
121-
if len(result) == 0:
122-
return None
123119

124-
return result
120+
result = list(chain(*[k for k in results if isinstance(k, list)]))
121+
if len(result) == 0:
122+
return None
123+
124+
return result
125125

126126
return None
127127

robotcode/language_server/common/parts/declaration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ async def _text_document_declaration(
8282
if len(locations) > 0 and len(location_links) == 0:
8383
if len(locations) == 1:
8484
return locations[0]
85-
else:
86-
return locations
85+
86+
return locations
8787

8888
if len(locations) > 0 and len(location_links) > 0:
8989
self._logger.warning("can't mix Locations and LocationLinks")

robotcode/language_server/common/parts/definition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ async def _text_document_definition(
8282
if len(locations) > 0 and len(location_links) == 0:
8383
if len(locations) == 1:
8484
return locations[0]
85-
else:
86-
return locations
85+
86+
return locations
8787

8888
if len(locations) > 0 and len(location_links) > 0:
8989
self._logger.warning("can't mix Locations and LocationLinks")

robotcode/language_server/common/parts/diagnostics.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -449,25 +449,26 @@ async def _get_diagnostics_for_document(
449449
if isinstance(result_any, BaseException):
450450
if not isinstance(result_any, asyncio.CancelledError):
451451
self._logger.exception(result_any, exc_info=result_any)
452-
elif result_any is None:
453452
continue
454-
else:
455-
result = cast(DiagnosticsResult, result_any)
456-
457-
data.id = str(uuid.uuid4())
458-
data.entries[result.key] = result.diagnostics
459-
if result.diagnostics is not None:
460-
collected_keys.append(result.key)
461-
462-
if data.entries and send_diagnostics:
463-
self.parent.send_notification(
464-
"textDocument/publishDiagnostics",
465-
PublishDiagnosticsParams(
466-
uri=document.document_uri,
467-
version=document._version,
468-
diagnostics=list(itertools.chain(*(i for i in data.entries.values() if i is not None))),
469-
),
470-
)
453+
if result_any is None:
454+
continue
455+
456+
result = cast(DiagnosticsResult, result_any)
457+
458+
data.id = str(uuid.uuid4())
459+
data.entries[result.key] = result.diagnostics
460+
if result.diagnostics is not None:
461+
collected_keys.append(result.key)
462+
463+
if data.entries and send_diagnostics:
464+
self.parent.send_notification(
465+
"textDocument/publishDiagnostics",
466+
PublishDiagnosticsParams(
467+
uri=document.document_uri,
468+
version=document._version,
469+
diagnostics=list(itertools.chain(*(i for i in data.entries.values() if i is not None))),
470+
),
471+
)
471472

472473
except asyncio.CancelledError:
473474
self._logger.debug(lambda: f"_get_diagnostics cancelled for {document}")

robotcode/language_server/common/parts/implementation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ async def _text_document_implementation(
8787
if len(locations) > 0 and len(location_links) == 0:
8888
if len(locations) == 1:
8989
return locations[0]
90-
else:
91-
return locations
90+
91+
return locations
9292

9393
if len(locations) > 0 and len(location_links) > 0:
9494
self._logger.warning("can't mix Locations and LocationLinks")

0 commit comments

Comments
 (0)