From e2fbc16a9097662748b9b6b512448f621bacbed9 Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Thu, 5 Dec 2024 16:55:33 +0100 Subject: [PATCH] style: enable ruff rules RUF021 and RUF022 --- .../core/src/robotcode/core/concurrent.py | 6 +-- packages/core/src/robotcode/core/event.py | 2 +- .../src/robotcode/core/utils/dataclasses.py | 10 ++-- .../src/robotcode/core/utils/glob_path.py | 4 +- .../core/src/robotcode/core/utils/logging.py | 2 +- .../src/robotcode/debugger/debugger.py | 29 +++++------- .../src/robotcode/jsonrpc2/protocol.py | 25 +++++----- .../language_server/common/parts/documents.py | 2 +- .../language_server/common/server.py | 2 +- .../parts/code_action_refactor.py | 38 ++++++--------- .../robotframework/parts/inlay_hint.py | 2 +- .../robotframework/parts/semantic_tokens.py | 9 ++-- .../plugin/src/robotcode/plugin/__init__.py | 10 ++-- .../robot/diagnostics/diagnostics_modifier.py | 2 +- .../robot/diagnostics/imports_manager.py | 3 +- .../robot/diagnostics/library_doc.py | 47 +++++++++++-------- .../robot/diagnostics/model_helper.py | 5 +- .../robot/src/robotcode/robot/utils/ast.py | 4 +- .../robot/utils/markdownformatter.py | 2 +- .../src/robotcode/runner/cli/__init__.py | 2 +- .../robotcode/runner/cli/discover/discover.py | 2 +- pyproject.toml | 2 +- scripts/generate_rf_options.py | 4 +- src/robotcode/cli/commands/profiles.py | 2 +- .../robotframework/parts/test_foldingrange.py | 13 ++--- 25 files changed, 109 insertions(+), 120 deletions(-) diff --git a/packages/core/src/robotcode/core/concurrent.py b/packages/core/src/robotcode/core/concurrent.py index 55c3624d6..ad0d99aff 100644 --- a/packages/core/src/robotcode/core/concurrent.py +++ b/packages/core/src/robotcode/core/concurrent.py @@ -145,10 +145,8 @@ def decorator(func: _F) -> _F: def is_threaded_callable(callable: Callable[..., Any]) -> bool: - return ( - getattr(callable, __THREADED_MARKER, False) - or inspect.ismethod(callable) - and getattr(callable, __THREADED_MARKER, False) + return getattr(callable, __THREADED_MARKER, False) or ( + inspect.ismethod(callable) and getattr(callable, __THREADED_MARKER, False) ) diff --git a/packages/core/src/robotcode/core/event.py b/packages/core/src/robotcode/core/event.py index 2b33ed47a..f30297f7a 100644 --- a/packages/core/src/robotcode/core/event.py +++ b/packages/core/src/robotcode/core/event.py @@ -19,7 +19,7 @@ from typing_extensions import ParamSpec -__all__ = ["event_iterator", "event"] +__all__ = ["event", "event_iterator"] _TResult = TypeVar("_TResult") _TParams = ParamSpec("_TParams") diff --git a/packages/core/src/robotcode/core/utils/dataclasses.py b/packages/core/src/robotcode/core/utils/dataclasses.py index 03e3f5d7b..15f623fd5 100644 --- a/packages/core/src/robotcode/core/utils/dataclasses.py +++ b/packages/core/src/robotcode/core/utils/dataclasses.py @@ -28,14 +28,14 @@ ) __all__ = [ - "to_snake_case", - "to_camel_case", + "CamelSnakeMixin", + "ValidateMixin", + "as_dict", "as_json", "from_dict", "from_json", - "as_dict", - "ValidateMixin", - "CamelSnakeMixin", + "to_camel_case", + "to_snake_case", ] _RE_SNAKE_CASE_1 = re.compile(r"[\-\.\s]") diff --git a/packages/core/src/robotcode/core/utils/glob_path.py b/packages/core/src/robotcode/core/utils/glob_path.py index 1245bd01f..e8564b8a3 100644 --- a/packages/core/src/robotcode/core/utils/glob_path.py +++ b/packages/core/src/robotcode/core/utils/glob_path.py @@ -164,7 +164,7 @@ def _iter_files_recursive_re( relative_path = (path / f.name).relative_to(_base_path) if not ignore_patterns or not any( - p.matches(relative_path) and (not p.only_dirs or p.only_dirs and f.is_dir()) + p.matches(relative_path) and (not p.only_dirs or (p.only_dirs and f.is_dir())) for p in cast(Iterable[Pattern], ignore_patterns) ): if f.is_dir(): @@ -177,7 +177,7 @@ def _iter_files_recursive_re( _base_path=_base_path, ) if not patterns or any( - p.matches(relative_path) and (not p.only_dirs or p.only_dirs and f.is_dir()) + p.matches(relative_path) and (not p.only_dirs or (p.only_dirs and f.is_dir())) for p in cast(Iterable[Pattern], patterns) ): yield Path(f).absolute() if absolute else Path(f) diff --git a/packages/core/src/robotcode/core/utils/logging.py b/packages/core/src/robotcode/core/utils/logging.py index aa7fac5c6..0e633e6e1 100644 --- a/packages/core/src/robotcode/core/utils/logging.py +++ b/packages/core/src/robotcode/core/utils/logging.py @@ -196,7 +196,7 @@ def log( extra: Optional[Mapping[str, object]] = None, **kwargs: Any, ) -> None: - if self.is_enabled_for(level) and condition is not None and condition() or condition is None: + if (self.is_enabled_for(level) and condition is not None and condition()) or condition is None: depth = 0 if context_name is not None: depth = self._measure_contexts.get(context_name, 0) diff --git a/packages/debugger/src/robotcode/debugger/debugger.py b/packages/debugger/src/robotcode/debugger/debugger.py index 7851b1d1b..558a20c27 100644 --- a/packages/debugger/src/robotcode/debugger/debugger.py +++ b/packages/debugger/src/robotcode/debugger/debugger.py @@ -1318,11 +1318,8 @@ def message(self, message: Dict[str, Any]) -> None: level = message["level"] current_frame = self.full_stack_frames[0] if self.full_stack_frames else None - if ( - self.output_messages - or current_frame is not None - and current_frame.type != "KEYWORD" - and level in ["FAIL", "ERROR", "WARN"] + if self.output_messages or ( + current_frame is not None and current_frame.type != "KEYWORD" and level in ["FAIL", "ERROR", "WARN"] ): self._send_log_event(message["timestamp"], level, message["message"], "messages") @@ -1599,10 +1596,8 @@ def evaluate( else evaluate_context.variables._global ) if ( - isinstance(context, EvaluateArgumentContext) - and context != EvaluateArgumentContext.REPL - or self.expression_mode - ): + isinstance(context, EvaluateArgumentContext) and context != EvaluateArgumentContext.REPL + ) or self.expression_mode: if expression.startswith("! "): splitted = self.SPLIT_LINE.split(expression[2:].strip()) @@ -1635,13 +1630,15 @@ def run_kw() -> Any: result = vars.replace_scalar(expression) except VariableError: if context is not None and ( - isinstance(context, EvaluateArgumentContext) - and ( - context - in [ - EvaluateArgumentContext.HOVER, - EvaluateArgumentContext.WATCH, - ] + ( + isinstance(context, EvaluateArgumentContext) + and ( + context + in [ + EvaluateArgumentContext.HOVER, + EvaluateArgumentContext.WATCH, + ] + ) ) or context in [ diff --git a/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py b/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py index 338144e75..4930c9625 100644 --- a/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py +++ b/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py @@ -40,24 +40,24 @@ from robotcode.core.utils.logging import LoggingDescriptor __all__ = [ - "JsonRPCErrors", - "JsonRPCMessage", - "JsonRPCNotification", - "JsonRPCRequest", - "JsonRPCResponse", + "GenericJsonRPCProtocolPart", + "InvalidProtocolVersionError", "JsonRPCError", + "JsonRPCErrorException", "JsonRPCErrorObject", - "JsonRPCProtocol", + "JsonRPCErrors", "JsonRPCException", + "JsonRPCMessage", + "JsonRPCNotification", "JsonRPCParseError", - "InvalidProtocolVersionError", - "rpc_method", - "RpcRegistry", + "JsonRPCProtocol", "JsonRPCProtocolPart", + "JsonRPCRequest", + "JsonRPCResponse", "ProtocolPartDescriptor", - "GenericJsonRPCProtocolPart", + "RpcRegistry", "TProtocol", - "JsonRPCErrorException", + "rpc_method", ] _T = TypeVar("_T") @@ -278,8 +278,7 @@ def get_methods(obj: Any) -> Dict[str, RpcMethodEntry]: iter_methods( obj, lambda m2: isinstance(m2, RpcMethod) - or inspect.ismethod(m2) - and isinstance(m2.__func__, RpcMethod), + or (inspect.ismethod(m2) and isinstance(m2.__func__, RpcMethod)), ), ) } diff --git a/packages/language_server/src/robotcode/language_server/common/parts/documents.py b/packages/language_server/src/robotcode/language_server/common/parts/documents.py index e92b30853..8989efda3 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/documents.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/documents.py @@ -40,7 +40,7 @@ from robotcode.language_server.common.protocol import LanguageServerProtocol -__all__ = ["TextDocumentProtocolPart", "LanguageServerDocumentError"] +__all__ = ["LanguageServerDocumentError", "TextDocumentProtocolPart"] class LanguageServerDocumentError(JsonRPCException): diff --git a/packages/language_server/src/robotcode/language_server/common/server.py b/packages/language_server/src/robotcode/language_server/common/server.py index 666ee37c7..94e189d53 100644 --- a/packages/language_server/src/robotcode/language_server/common/server.py +++ b/packages/language_server/src/robotcode/language_server/common/server.py @@ -6,7 +6,7 @@ from .protocol import LanguageServerProtocol -__all__ = ["LanguageServerBase", "TCP_DEFAULT_PORT"] +__all__ = ["TCP_DEFAULT_PORT", "LanguageServerBase"] TCP_DEFAULT_PORT = 6610 diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py index 387311a1a..741bf417d 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py @@ -194,23 +194,18 @@ def get_valid_nodes_in_range(self, model: ast.AST, range: Range, also_return: bo r = range_from_node(node, skip_non_data=True, allow_comments=True) if r.is_in_range(range): - if ( - isinstance( - node, - ( - Fixture, - Documentation, - MultiValue, - SingleValue, - TestCaseName, - KeywordName, - TemplateArguments, - ), - ) - or also_return - and get_robot_version() >= (5, 0, 0) - and isinstance(node, ReturnStatement) - ): + if isinstance( + node, + ( + Fixture, + Documentation, + MultiValue, + SingleValue, + TestCaseName, + KeywordName, + TemplateArguments, + ), + ) or (also_return and get_robot_version() >= (5, 0, 0) and isinstance(node, ReturnStatement)): return [] result.append(node) @@ -246,8 +241,7 @@ def get_valid_nodes_in_range(self, model: ast.AST, range: Range, also_return: bo n for n in result if isinstance(n, (IfHeader, ElseIfHeader, ElseHeader, ForHeader, End)) - or get_robot_version() >= (5, 0) - and isinstance(n, (WhileHeader, TryHeader, ExceptHeader, FinallyHeader)) + or (get_robot_version() >= (5, 0) and isinstance(n, (WhileHeader, TryHeader, ExceptHeader, FinallyHeader))) ): return [] @@ -255,10 +249,8 @@ def get_valid_nodes_in_range(self, model: ast.AST, range: Range, also_return: bo n for n in result if isinstance(n, (Continue, Break)) - or isinstance(n, Try) - and n.type in [RobotToken.EXCEPT, RobotToken.FINALLY, RobotToken.ELSE] - or also_return - and isinstance(n, ReturnStatement) + or (isinstance(n, Try) and n.type in [RobotToken.EXCEPT, RobotToken.FINALLY, RobotToken.ELSE]) + or (also_return and isinstance(n, ReturnStatement)) ): return [] diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/inlay_hint.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/inlay_hint.py index eed9d5e37..0850edbd2 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/inlay_hint.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/inlay_hint.py @@ -69,7 +69,7 @@ def _find_method(self, cls: Type[Any]) -> Optional[_HandlerMethod]: @_logger.call def collect(self, sender: Any, document: TextDocument, range: Range) -> Optional[List[InlayHint]]: config = self.get_config(document) - if config is None or not config.parameter_names and not config.namespaces: + if config is None or (not config.parameter_names and not config.namespaces): return None model = self.parent.documents_cache.get_model(document, False) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py index 517ede742..a8569cfec 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py @@ -620,8 +620,7 @@ def generate_sem_sub_tokens( if ( yield_arguments or token.type != Token.ARGUMENT - or token.type != Token.NAME - and cached_isinstance(node, Metadata) + or (token.type != Token.NAME and cached_isinstance(node, Metadata)) ): yield SemTokenInfo.from_token(token, sem_type, sem_mod, col_offset, length) @@ -632,10 +631,8 @@ def generate_sem_tokens( namespace: Namespace, builtin_library_doc: Optional[LibraryDoc], ) -> Iterator[SemTokenInfo]: - if ( - token.type in {Token.ARGUMENT, Token.TESTCASE_NAME, Token.KEYWORD_NAME} - or token.type == Token.NAME - and cached_isinstance(node, VariablesImport, LibraryImport, ResourceImport) + if token.type in {Token.ARGUMENT, Token.TESTCASE_NAME, Token.KEYWORD_NAME} or ( + token.type == Token.NAME and cached_isinstance(node, VariablesImport, LibraryImport, ResourceImport) ): if ( cached_isinstance(node, Variable) and token.type == Token.ARGUMENT and node.name and node.name[0] == "&" diff --git a/packages/plugin/src/robotcode/plugin/__init__.py b/packages/plugin/src/robotcode/plugin/__init__.py index ad3986039..30ae09e93 100644 --- a/packages/plugin/src/robotcode/plugin/__init__.py +++ b/packages/plugin/src/robotcode/plugin/__init__.py @@ -27,13 +27,13 @@ from robotcode.core.utils.dataclasses import as_dict, as_json __all__ = [ - "hookimpl", - "CommonConfig", - "pass_application", "Application", - "UnknownError", - "OutputFormat", "ColoredOutput", + "CommonConfig", + "OutputFormat", + "UnknownError", + "hookimpl", + "pass_application", ] F = TypeVar("F", bound=Callable[..., Any]) diff --git a/packages/robot/src/robotcode/robot/diagnostics/diagnostics_modifier.py b/packages/robot/src/robotcode/robot/diagnostics/diagnostics_modifier.py index b4436c196..a48fc2b5b 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/diagnostics_modifier.py +++ b/packages/robot/src/robotcode/robot/diagnostics/diagnostics_modifier.py @@ -209,7 +209,7 @@ def modify_diagnostic(self, diagnostic: Diagnostic) -> Optional[Diagnostic]: lines = self.rules_and_codes.codes.get(code) - if lines is None or lines is not None and diagnostic.range.start.line not in lines: + if lines is None or (lines is not None and diagnostic.range.start.line not in lines): code = "*" lines = self.rules_and_codes.codes.get(code) diff --git a/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py b/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py index 606063e93..e4b35298d 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py +++ b/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py @@ -322,8 +322,7 @@ def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileChangeTyp if ( self._document is not None and (normalized_path(path) == normalized_path(self._document.uri.to_path())) - or self._document is None - ): + ) or self._document is None: self._invalidate() return change.type diff --git a/packages/robot/src/robotcode/robot/diagnostics/library_doc.py b/packages/robot/src/robotcode/robot/diagnostics/library_doc.py index 0b78bff00..4254c2a89 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/library_doc.py +++ b/packages/robot/src/robotcode/robot/diagnostics/library_doc.py @@ -1824,7 +1824,11 @@ def get_library_doc( if module_spec is not None and module_spec.origin else import_name if is_library_by_path(import_name) else None ), - 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, + ( + 1 + if source is not None or (module_spec is not None and module_spec.origin is not None) + else None + ), ) ], python_path=sys.path, @@ -1868,7 +1872,7 @@ def get_library_doc( error_from_exception( e, source or module_spec.origin if module_spec is not None else None, - 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, + 1 if source is not None or (module_spec is not None and module_spec.origin is not None) else None, ) ) @@ -1919,7 +1923,8 @@ def _get(handler: Callable[[], _T]) -> Optional[_T]: source or module_spec.origin if module_spec is not None else None, ( 1 - if source is not None or module_spec is not None and module_spec.origin is not None + if source is not None + or (module_spec is not None and module_spec.origin is not None) else None ), ) @@ -2119,7 +2124,11 @@ def _get_type_docs(keywords: List[Any], custom_converters: List[Any]) -> Set[Rob error_from_exception( e, source or module_spec.origin if module_spec is not None else None, - 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, + ( + 1 + if source is not None or (module_spec is not None and module_spec.origin is not None) + else None + ), ) ) @@ -2412,7 +2421,11 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any: if module_spec is not None and module_spec.origin else import_name if is_variables_by_path(import_name) else None ), - 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, + ( + 1 + if source is not None or (module_spec is not None and module_spec.origin is not None) + else None + ), ) ] @@ -2432,7 +2445,7 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any: if module_spec is not None and module_spec.origin else import_name if is_variables_by_path(import_name) else None ), - 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, + 1 if source is not None or (module_spec is not None and module_spec.origin is not None) else None, ) ], python_path=sys.path, @@ -2480,7 +2493,7 @@ def is_file_like(name: Optional[str]) -> bool: return False base, filename = os.path.split(name) - return name.startswith(".") or bool(base) and filename != name + return name.startswith(".") or (bool(base) and filename != name) def iter_module_names(name: Optional[str] = None) -> Iterator[str]: @@ -2522,10 +2535,8 @@ def iter_modules_from_python_path( if e.is_dir(): for f in e.iterdir(): if not f.name.startswith(("_", ".")) and ( - f.is_file() - and f.suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS - or f.is_dir() - and f.suffix not in NOT_WANTED_DIR_EXTENSIONS + (f.is_file() and f.suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS) + or (f.is_dir() and f.suffix not in NOT_WANTED_DIR_EXTENSIONS) ): if f.is_dir(): yield CompleteResult(f.name, CompleteResultKind.MODULE) @@ -2586,8 +2597,7 @@ def complete_library_import( if not f.name.startswith(("_", ".")) and ( (f.is_file() and f.suffix in ALLOWED_LIBRARY_FILE_EXTENSIONS) - or f.is_dir() - and f.suffix not in NOT_WANTED_DIR_EXTENSIONS + or (f.is_dir() and f.suffix not in NOT_WANTED_DIR_EXTENSIONS) ) ] @@ -2606,10 +2616,8 @@ def iter_resources_from_python_path( if e.is_dir(): for f in e.iterdir(): if not f.name.startswith(("_", ".")) and ( - f.is_file() - and f.suffix in ALLOWED_RESOURCE_FILE_EXTENSIONS - or f.is_dir() - and f.suffix not in NOT_WANTED_DIR_EXTENSIONS + (f.is_file() and f.suffix in ALLOWED_RESOURCE_FILE_EXTENSIONS) + or (f.is_dir() and f.suffix not in NOT_WANTED_DIR_EXTENSIONS) ): yield CompleteResult( f.name, @@ -2633,7 +2641,7 @@ def complete_resource_import( name = robot_variables.replace_string(name, ignore_errors=True) - if name is None or not name.startswith(".") and not name.startswith("/") and not name.startswith(os.sep): + if name is None or (not name.startswith(".") and not name.startswith("/") and not name.startswith(os.sep)): result += list(iter_resources_from_python_path(name)) if name is None or name.startswith((".", "/", os.sep)): @@ -2702,8 +2710,7 @@ def complete_variables_import( if not f.name.startswith(("_", ".")) and ( (f.is_file() and f.suffix in ALLOWED_VARIABLES_FILE_EXTENSIONS) - or f.is_dir() - and f.suffix not in NOT_WANTED_DIR_EXTENSIONS + or (f.is_dir() and f.suffix not in NOT_WANTED_DIR_EXTENSIONS) ) ] diff --git a/packages/robot/src/robotcode/robot/diagnostics/model_helper.py b/packages/robot/src/robotcode/robot/diagnostics/model_helper.py index b790e4b40..5c95080e9 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/model_helper.py +++ b/packages/robot/src/robotcode/robot/diagnostics/model_helper.py @@ -749,9 +749,8 @@ def get_argument_info_at_position( if argument_token_index < len(tokens) and tokens[argument_token_index].type == Token.ARGUMENT: argument_token = tokens[argument_token_index] - if ( - argument_index < 0 - or argument_token is not None + if argument_index < 0 or ( + argument_token is not None and argument_token.type == Token.ARGUMENT and argument_token.value.startswith(("@{", "&{")) and argument_token.value.endswith("}") diff --git a/packages/robot/src/robotcode/robot/utils/ast.py b/packages/robot/src/robotcode/robot/utils/ast.py index a6731930b..bd130b742 100644 --- a/packages/robot/src/robotcode/robot/utils/ast.py +++ b/packages/robot/src/robotcode/robot/utils/ast.py @@ -205,7 +205,7 @@ def get_tokens_at_position(node: Statement, position: Position, include_end: boo return [ t for t in node.tokens - if position.is_in_range(range := range_from_token(t), include_end) or include_end and range.end == position + if position.is_in_range(range := range_from_token(t), include_end) or (include_end and range.end == position) ] @@ -214,7 +214,7 @@ def iter_nodes_at_position(node: ast.AST, position: Position, include_end: bool yield node for n in iter_nodes(node): - if position.is_in_range(range := range_from_node(n), include_end) or include_end and range.end == position: + if position.is_in_range(range := range_from_node(n), include_end) or (include_end and range.end == position): yield n diff --git a/packages/robot/src/robotcode/robot/utils/markdownformatter.py b/packages/robot/src/robotcode/robot/utils/markdownformatter.py index 0c919c4cb..efb2d3dea 100644 --- a/packages/robot/src/robotcode/robot/utils/markdownformatter.py +++ b/packages/robot/src/robotcode/robot/utils/markdownformatter.py @@ -276,7 +276,7 @@ class ListFormatter(Formatter): _strip_lines = False def _handles(self, line: str) -> bool: - return bool(line.strip().startswith("- ") or line.startswith(" ") and self._lines) + return bool(line.strip().startswith("- ") or (line.startswith(" ") and self._lines)) def format(self, lines: List[str]) -> str: items = ["- %s" % _line_formatter.format(line) for line in self._combine_lines(lines)] diff --git a/packages/runner/src/robotcode/runner/cli/__init__.py b/packages/runner/src/robotcode/runner/cli/__init__.py index 6b7f913b3..a0005e938 100644 --- a/packages/runner/src/robotcode/runner/cli/__init__.py +++ b/packages/runner/src/robotcode/runner/cli/__init__.py @@ -4,4 +4,4 @@ from .robot import robot from .testdoc import testdoc -__all__ = ["robot", "libdoc", "rebot", "testdoc", "discover"] +__all__ = ["discover", "libdoc", "rebot", "robot", "testdoc"] diff --git a/packages/runner/src/robotcode/runner/cli/discover/discover.py b/packages/runner/src/robotcode/runner/cli/discover/discover.py index 9a40135bf..56fc6d5ae 100644 --- a/packages/runner/src/robotcode/runner/cli/discover/discover.py +++ b/packages/runner/src/robotcode/runner/cli/discover/discover.py @@ -72,7 +72,7 @@ def _patch() -> None: __patched = True if get_robot_version() < (6, 1): - if get_robot_version() > (5, 0) and get_robot_version() < (6, 0) or get_robot_version() < (5, 0): + if (get_robot_version() > (5, 0) and get_robot_version() < (6, 0)) or get_robot_version() < (5, 0): from robot.running.builder.testsettings import ( # pyright: ignore[reportMissingImports] TestDefaults, ) diff --git a/pyproject.toml b/pyproject.toml index 3f3a585e4..540fe8791 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -175,7 +175,7 @@ target-version = "py38" extend-exclude = ["bundled/libs", ".hatch"] [tool.ruff.lint] -ignore = ["E741", "N805", "N999", "RUF012", "RUF006", "ISC001", "RUF021", "RUF022"] +ignore = ["E741", "N805", "N999", "RUF012", "RUF006", "ISC001"] select = [ "E", "F", diff --git a/scripts/generate_rf_options.py b/scripts/generate_rf_options.py index 978673b9b..8330322f7 100644 --- a/scripts/generate_rf_options.py +++ b/scripts/generate_rf_options.py @@ -164,7 +164,7 @@ def get_type( has_literal = [x for x in param_splitted if ":" not in x] has_pattern = [x for x in param_splitted if ":" in x] base_type = ( - ("Union[str, " if has_literal and has_pattern or len(has_pattern) > 1 else "") + ("Union[str, " if (has_literal and has_pattern) or len(has_pattern) > 1 else "") + (("Literal[" + ", ".join([f'"{x}"' for x in has_literal]) + "]") if has_literal else "") + ( ( @@ -176,7 +176,7 @@ def get_type( if has_pattern else "" ) - + ("]" if has_literal and has_pattern or len(has_pattern) > 1 else "") + + ("]" if (has_literal and has_pattern) or len(has_pattern) > 1 else "") ) elif len(param_splitted := param.split(":")) > 1: diff --git a/src/robotcode/cli/commands/profiles.py b/src/robotcode/cli/commands/profiles.py index 75c9918a5..ea32c45f5 100644 --- a/src/robotcode/cli/commands/profiles.py +++ b/src/robotcode/cli/commands/profiles.py @@ -102,7 +102,7 @@ def list(app: Application, paths: List[Path], show_hidden: bool = False, sort_by "precedence": v.precedence, } for k, v in (config.profiles or {}).items() - if show_hidden or not k.startswith("_") and not v.hidden + if show_hidden or (not k.startswith("_") and not v.hidden) ], key=( (lambda v: cast(Any, str(v.get("name", "")))) diff --git a/tests/robotcode/language_server/robotframework/parts/test_foldingrange.py b/tests/robotcode/language_server/robotframework/parts/test_foldingrange.py index 80a1ac5f9..24018528d 100644 --- a/tests/robotcode/language_server/robotframework/parts/test_foldingrange.py +++ b/tests/robotcode/language_server/robotframework/parts/test_foldingrange.py @@ -75,12 +75,13 @@ def test( result = [ r for r in result - if "start" in data.name.lower() - and r.start_line == data.line - or "end" in data.name.lower() - and r.end_line - == data.line - - (0 if ("else" in data.name.lower() or "if" in data.name.lower() or "for" in data.name.lower()) else 1) + if ("start" in data.name.lower() and r.start_line == data.line) + or ( + "end" in data.name.lower() + and r.end_line + == data.line + - (0 if ("else" in data.name.lower() or "if" in data.name.lower() or "for" in data.name.lower()) else 1) + ) ] assert result regtest.write(yaml.dump({"data": data, "result": result}))