Skip to content

Commit 9403f72

Browse files
committed
refactor: simplify some code
1 parent 657a4fc commit 9403f72

File tree

9 files changed

+26
-36
lines changed

9 files changed

+26
-36
lines changed

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ select = [
274274
# "T20",
275275
"PT",
276276
"Q",
277-
"RET"
277+
"RET",
278+
# "SIM", # TODO enable this
279+
#"TID",
280+
#"TCH",
281+
#"ARG",
282+
#"PTH", # TODO enable this
278283
]
279284

280285

robotcode/debugger/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import asyncio
3+
import contextlib
34
import functools
45
import logging
56
import logging.config
@@ -32,10 +33,8 @@
3233
if str(top) not in sys.path:
3334
sys.path.append(str(top))
3435

35-
try:
36+
with contextlib.suppress(ValueError):
3637
sys.path.remove(str(parent))
37-
except ValueError: # Already removed
38-
pass
3938

4039
__package__ = "robotcode.debugger"
4140

robotcode/debugger/debugger.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,18 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
489489
),
490490
)
491491
self.requested_state = RequestedState.Nothing
492-
elif self.requested_state == RequestedState.StepOut:
493-
if len(self.full_stack_frames) <= self.stop_stack_len:
494-
self.state = State.Paused
495-
self.send_event(
496-
self,
497-
StoppedEvent(
498-
body=StoppedEventBody(
499-
reason=StoppedReason.STEP,
500-
thread_id=threading.current_thread().ident,
501-
)
502-
),
503-
)
504-
self.requested_state = RequestedState.Nothing
492+
elif self.requested_state == RequestedState.StepOut and len(self.full_stack_frames) <= self.stop_stack_len:
493+
self.state = State.Paused
494+
self.send_event(
495+
self,
496+
StoppedEvent(
497+
body=StoppedEventBody(
498+
reason=StoppedReason.STEP,
499+
thread_id=threading.current_thread().ident,
500+
)
501+
),
502+
)
503+
self.requested_state = RequestedState.Nothing
505504

506505
if source is not None:
507506
source_path = self.map_path_to_client(str(Path(source).absolute()))

robotcode/jsonrpc2/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def get_methods(obj: Any) -> Dict[str, RpcMethodEntry]:
283283
if r is not None:
284284
registries.insert(0, r)
285285
for r in registries:
286-
for k in r.__class_parts.keys():
286+
for k in r.__class_parts:
287287
getattr(self.__owner, k)
288288

289289
self.__methods = get_methods(self.__owner)

robotcode/language_server/common/parts/diagnostics.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,7 @@ async def run_workspace_diagnostics(self) -> None:
353353
progress.begin()
354354
path = document.uri.to_path()
355355
folder = self.parent.workspace.get_workspace_folder(document.uri)
356-
if folder is None:
357-
name = path
358-
else:
359-
name = path.relative_to(folder.uri.to_path())
356+
name = path if folder is None else path.relative_to(folder.uri.to_path())
360357

361358
progress.report(f"Analyse {name}", current=i + 1)
362359
elif analysis_mode == AnalysisProgressMode.SIMPLE:

robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __repr__(self) -> str:
194194
return f"{type(self).__name__}(name={repr(self.name)})"
195195

196196

197-
RUN_KEYWORD_WITH_CONDITION_MATCHERS = [KeywordMatcher(e) for e in RUN_KEYWORD_WITH_CONDITION_NAMES.keys()]
197+
RUN_KEYWORD_WITH_CONDITION_MATCHERS = [KeywordMatcher(e) for e in RUN_KEYWORD_WITH_CONDITION_NAMES]
198198

199199
RUN_KEYWORD_IF_MATCHER = KeywordMatcher(RUN_KEYWORD_IF_NAME)
200200

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,11 +1668,7 @@ def _should_ignore(self, range: Range) -> bool:
16681668
def __should_ignore(lines: List[int], range: Range) -> bool:
16691669
import builtins
16701670

1671-
for line_no in builtins.range(range.start.line, range.end.line + 1):
1672-
if line_no in lines:
1673-
return True
1674-
1675-
return False
1671+
return any(line_no in lines for line_no in builtins.range(range.start.line, range.end.line + 1))
16761672

16771673

16781674
class DiagnosticsEntry(NamedTuple):

robotcode/language_server/robotframework/utils/robot_path.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def find_file_ex(
2222
from robot.errors import DataError
2323

2424
path = Path(path)
25-
if path.is_absolute():
26-
ret = _find_absolute_path(path)
27-
else:
28-
ret = _find_relative_path(path, basedir)
25+
ret = _find_absolute_path(path) if path.is_absolute() else _find_relative_path(path, basedir)
2926
if ret:
3027
return str(ret)
3128
default = file_type or "File"

scripts/is_prerelease.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
def main() -> None:
55

66
version = get_version()
7-
if version.prerelease:
8-
preview = 1
9-
else:
10-
preview = 0
7+
preview = 1 if version.prerelease else 0
118

129
print(preview)
1310

0 commit comments

Comments
 (0)