Skip to content

Commit e2fbc16

Browse files
committed
style: enable ruff rules RUF021 and RUF022
1 parent 9185ccd commit e2fbc16

File tree

25 files changed

+109
-120
lines changed

25 files changed

+109
-120
lines changed

packages/core/src/robotcode/core/concurrent.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ def decorator(func: _F) -> _F:
145145

146146

147147
def is_threaded_callable(callable: Callable[..., Any]) -> bool:
148-
return (
149-
getattr(callable, __THREADED_MARKER, False)
150-
or inspect.ismethod(callable)
151-
and getattr(callable, __THREADED_MARKER, False)
148+
return getattr(callable, __THREADED_MARKER, False) or (
149+
inspect.ismethod(callable) and getattr(callable, __THREADED_MARKER, False)
152150
)
153151

154152

packages/core/src/robotcode/core/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from typing_extensions import ParamSpec
2121

22-
__all__ = ["event_iterator", "event"]
22+
__all__ = ["event", "event_iterator"]
2323

2424
_TResult = TypeVar("_TResult")
2525
_TParams = ParamSpec("_TParams")

packages/core/src/robotcode/core/utils/dataclasses.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
)
2929

3030
__all__ = [
31-
"to_snake_case",
32-
"to_camel_case",
31+
"CamelSnakeMixin",
32+
"ValidateMixin",
33+
"as_dict",
3334
"as_json",
3435
"from_dict",
3536
"from_json",
36-
"as_dict",
37-
"ValidateMixin",
38-
"CamelSnakeMixin",
37+
"to_camel_case",
38+
"to_snake_case",
3939
]
4040

4141
_RE_SNAKE_CASE_1 = re.compile(r"[\-\.\s]")

packages/core/src/robotcode/core/utils/glob_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _iter_files_recursive_re(
164164
relative_path = (path / f.name).relative_to(_base_path)
165165

166166
if not ignore_patterns or not any(
167-
p.matches(relative_path) and (not p.only_dirs or p.only_dirs and f.is_dir())
167+
p.matches(relative_path) and (not p.only_dirs or (p.only_dirs and f.is_dir()))
168168
for p in cast(Iterable[Pattern], ignore_patterns)
169169
):
170170
if f.is_dir():
@@ -177,7 +177,7 @@ def _iter_files_recursive_re(
177177
_base_path=_base_path,
178178
)
179179
if not patterns or any(
180-
p.matches(relative_path) and (not p.only_dirs or p.only_dirs and f.is_dir())
180+
p.matches(relative_path) and (not p.only_dirs or (p.only_dirs and f.is_dir()))
181181
for p in cast(Iterable[Pattern], patterns)
182182
):
183183
yield Path(f).absolute() if absolute else Path(f)

packages/core/src/robotcode/core/utils/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def log(
196196
extra: Optional[Mapping[str, object]] = None,
197197
**kwargs: Any,
198198
) -> None:
199-
if self.is_enabled_for(level) and condition is not None and condition() or condition is None:
199+
if (self.is_enabled_for(level) and condition is not None and condition()) or condition is None:
200200
depth = 0
201201
if context_name is not None:
202202
depth = self._measure_contexts.get(context_name, 0)

packages/debugger/src/robotcode/debugger/debugger.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,8 @@ def message(self, message: Dict[str, Any]) -> None:
13181318
level = message["level"]
13191319
current_frame = self.full_stack_frames[0] if self.full_stack_frames else None
13201320

1321-
if (
1322-
self.output_messages
1323-
or current_frame is not None
1324-
and current_frame.type != "KEYWORD"
1325-
and level in ["FAIL", "ERROR", "WARN"]
1321+
if self.output_messages or (
1322+
current_frame is not None and current_frame.type != "KEYWORD" and level in ["FAIL", "ERROR", "WARN"]
13261323
):
13271324
self._send_log_event(message["timestamp"], level, message["message"], "messages")
13281325

@@ -1599,10 +1596,8 @@ def evaluate(
15991596
else evaluate_context.variables._global
16001597
)
16011598
if (
1602-
isinstance(context, EvaluateArgumentContext)
1603-
and context != EvaluateArgumentContext.REPL
1604-
or self.expression_mode
1605-
):
1599+
isinstance(context, EvaluateArgumentContext) and context != EvaluateArgumentContext.REPL
1600+
) or self.expression_mode:
16061601
if expression.startswith("! "):
16071602
splitted = self.SPLIT_LINE.split(expression[2:].strip())
16081603

@@ -1635,13 +1630,15 @@ def run_kw() -> Any:
16351630
result = vars.replace_scalar(expression)
16361631
except VariableError:
16371632
if context is not None and (
1638-
isinstance(context, EvaluateArgumentContext)
1639-
and (
1640-
context
1641-
in [
1642-
EvaluateArgumentContext.HOVER,
1643-
EvaluateArgumentContext.WATCH,
1644-
]
1633+
(
1634+
isinstance(context, EvaluateArgumentContext)
1635+
and (
1636+
context
1637+
in [
1638+
EvaluateArgumentContext.HOVER,
1639+
EvaluateArgumentContext.WATCH,
1640+
]
1641+
)
16451642
)
16461643
or context
16471644
in [

packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@
4040
from robotcode.core.utils.logging import LoggingDescriptor
4141

4242
__all__ = [
43-
"JsonRPCErrors",
44-
"JsonRPCMessage",
45-
"JsonRPCNotification",
46-
"JsonRPCRequest",
47-
"JsonRPCResponse",
43+
"GenericJsonRPCProtocolPart",
44+
"InvalidProtocolVersionError",
4845
"JsonRPCError",
46+
"JsonRPCErrorException",
4947
"JsonRPCErrorObject",
50-
"JsonRPCProtocol",
48+
"JsonRPCErrors",
5149
"JsonRPCException",
50+
"JsonRPCMessage",
51+
"JsonRPCNotification",
5252
"JsonRPCParseError",
53-
"InvalidProtocolVersionError",
54-
"rpc_method",
55-
"RpcRegistry",
53+
"JsonRPCProtocol",
5654
"JsonRPCProtocolPart",
55+
"JsonRPCRequest",
56+
"JsonRPCResponse",
5757
"ProtocolPartDescriptor",
58-
"GenericJsonRPCProtocolPart",
58+
"RpcRegistry",
5959
"TProtocol",
60-
"JsonRPCErrorException",
60+
"rpc_method",
6161
]
6262

6363
_T = TypeVar("_T")
@@ -278,8 +278,7 @@ def get_methods(obj: Any) -> Dict[str, RpcMethodEntry]:
278278
iter_methods(
279279
obj,
280280
lambda m2: isinstance(m2, RpcMethod)
281-
or inspect.ismethod(m2)
282-
and isinstance(m2.__func__, RpcMethod),
281+
or (inspect.ismethod(m2) and isinstance(m2.__func__, RpcMethod)),
283282
),
284283
)
285284
}

packages/language_server/src/robotcode/language_server/common/parts/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from robotcode.language_server.common.protocol import LanguageServerProtocol
4141

4242

43-
__all__ = ["TextDocumentProtocolPart", "LanguageServerDocumentError"]
43+
__all__ = ["LanguageServerDocumentError", "TextDocumentProtocolPart"]
4444

4545

4646
class LanguageServerDocumentError(JsonRPCException):

packages/language_server/src/robotcode/language_server/common/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .protocol import LanguageServerProtocol
88

9-
__all__ = ["LanguageServerBase", "TCP_DEFAULT_PORT"]
9+
__all__ = ["TCP_DEFAULT_PORT", "LanguageServerBase"]
1010

1111
TCP_DEFAULT_PORT = 6610
1212

packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,18 @@ def get_valid_nodes_in_range(self, model: ast.AST, range: Range, also_return: bo
194194

195195
r = range_from_node(node, skip_non_data=True, allow_comments=True)
196196
if r.is_in_range(range):
197-
if (
198-
isinstance(
199-
node,
200-
(
201-
Fixture,
202-
Documentation,
203-
MultiValue,
204-
SingleValue,
205-
TestCaseName,
206-
KeywordName,
207-
TemplateArguments,
208-
),
209-
)
210-
or also_return
211-
and get_robot_version() >= (5, 0, 0)
212-
and isinstance(node, ReturnStatement)
213-
):
197+
if isinstance(
198+
node,
199+
(
200+
Fixture,
201+
Documentation,
202+
MultiValue,
203+
SingleValue,
204+
TestCaseName,
205+
KeywordName,
206+
TemplateArguments,
207+
),
208+
) or (also_return and get_robot_version() >= (5, 0, 0) and isinstance(node, ReturnStatement)):
214209
return []
215210

216211
result.append(node)
@@ -246,19 +241,16 @@ def get_valid_nodes_in_range(self, model: ast.AST, range: Range, also_return: bo
246241
n
247242
for n in result
248243
if isinstance(n, (IfHeader, ElseIfHeader, ElseHeader, ForHeader, End))
249-
or get_robot_version() >= (5, 0)
250-
and isinstance(n, (WhileHeader, TryHeader, ExceptHeader, FinallyHeader))
244+
or (get_robot_version() >= (5, 0) and isinstance(n, (WhileHeader, TryHeader, ExceptHeader, FinallyHeader)))
251245
):
252246
return []
253247

254248
if get_robot_version() >= (5, 0, 0) and any(
255249
n
256250
for n in result
257251
if isinstance(n, (Continue, Break))
258-
or isinstance(n, Try)
259-
and n.type in [RobotToken.EXCEPT, RobotToken.FINALLY, RobotToken.ELSE]
260-
or also_return
261-
and isinstance(n, ReturnStatement)
252+
or (isinstance(n, Try) and n.type in [RobotToken.EXCEPT, RobotToken.FINALLY, RobotToken.ELSE])
253+
or (also_return and isinstance(n, ReturnStatement))
262254
):
263255
return []
264256

0 commit comments

Comments
 (0)