Skip to content

Commit 1161451

Browse files
committed
refactor: fix some ruff warnings
1 parent 5aba99b commit 1161451

File tree

23 files changed

+49
-60
lines changed

23 files changed

+49
-60
lines changed

packages/core/src/robotcode/core/async_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def set_result(w: asyncio.Future[Any], ev: threading.Event) -> None:
523523

524524
time.sleep(0.001)
525525
else:
526-
warnings.warn(f"Future {repr(fut)} loop is closed")
526+
warnings.warn(f"Future {fut!r} loop is closed")
527527
self._waiters.remove(fut)
528528
self._wake_up_first()
529529

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __default(o: Any) -> Any:
172172
if isinstance(o, Set):
173173
return list(o)
174174

175-
raise TypeError(f"Cant' get default value for {type(o)} with value {repr(o)}")
175+
raise TypeError(f"Cant' get default value for {type(o)} with value {o!r}")
176176

177177

178178
def as_json(obj: Any, indent: Optional[bool] = None, compact: Optional[bool] = None) -> str:
@@ -298,7 +298,7 @@ def from_dict(
298298
match_type_hints = type_hints
299299
elif match_same_keys is not None and len(match_same_keys) == len(same_keys):
300300
raise TypeError(
301-
f"Value {repr(value)} matches to more then one types of "
301+
f"Value {value!r} matches to more then one types of "
302302
f"{repr(types[0].__name__) if len(types)==1 else ' | '.join(repr(e.__name__) for e in types)}."
303303
)
304304

@@ -317,7 +317,7 @@ def from_dict(
317317
try:
318318
return match_(**params)
319319
except TypeError as ex:
320-
raise TypeError(f"Can't initialize class {repr(match_)} with parameters {repr(params)}.") from ex
320+
raise TypeError(f"Can't initialize class {match_!r} with parameters {params!r}.") from ex
321321

322322
for t in types:
323323
args = get_args(t)
@@ -332,7 +332,7 @@ def from_dict(
332332
return cast(_T, v)
333333

334334
raise TypeError(
335-
f"Cant convert value {repr(value)} of type {type(value).__name__} to type(s) "
335+
f"Cant convert value {value!r} of type {type(value).__name__} to type(s) "
336336
+ (
337337
repr(types[0])
338338
if len(types) == 1
@@ -415,13 +415,13 @@ def __repr__(self) -> str:
415415
cls = self.class_
416416
cls_name = f"{cls.__module__}.{cls.__name__}" if cls.__module__ != "__main__" else cls.__name__
417417
attrs = ", ".join([repr(v) for v in self.args])
418-
return f"{cls_name}({attrs}, errors={repr(self.errors)})"
418+
return f"{cls_name}({attrs}, errors={self.errors!r})"
419419

420420
def __str__(self) -> str:
421421
cls = self.class_
422422
cls_name = f"{cls.__module__}.{cls.__name__}" if cls.__module__ != "__main__" else cls.__name__
423423
s = cls_name
424-
return f"{s} (errors = {repr(self.errors)})"
424+
return f"{s} (errors = {self.errors!r})"
425425

426426

427427
def validate_types(expected_types: Union[type, Tuple[type, ...], None], value: Any) -> List[str]:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def name(self) -> str:
307307
def __repr__(self) -> str:
308308
logger = self.logger
309309
level = logging.getLevelName(logger.getEffectiveLevel())
310-
return f"{self.__class__.__name__}(name={repr(logger.name)}, level={repr(level)})"
310+
return f"{self.__class__.__name__}(name={logger.name!r}, level={level!r})"
311311

312312
_call_tracing_enabled: ClassVar = (
313313
"ROBOT_CALL_TRACING_ENABLED" in os.environ and os.environ["ROBOT_CALL_TRACING_ENABLED"] != "0"
@@ -438,7 +438,7 @@ def build_enter_message() -> str:
438438
", ".join(_repr(a) for a in message_args),
439439
(", " if len(message_args) > 0 and len(wrapper_kwargs) > 0 else ""),
440440
(
441-
", ".join(f"{str(k)}={_repr(v)}" for k, v in wrapper_kwargs.items())
441+
", ".join(f"{k!s}={_repr(v)}" for k, v in wrapper_kwargs.items())
442442
if len(wrapper_kwargs) > 0
443443
else ""
444444
),

packages/core/src/robotcode/core/uri.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __str__(self) -> str:
9393
return parse.urlunparse(tuple(self._parts))
9494

9595
def __repr__(self) -> str:
96-
return f"{type(self).__name__}({repr(parse.urlunparse(tuple(self._parts)))})"
96+
return f"{type(self).__name__}({parse.urlunparse(tuple(self._parts))!r})"
9797

9898
def to_path(self) -> Path:
9999
if self._path is None:
@@ -112,7 +112,7 @@ def _to_path_str(self) -> str:
112112
path = parse.unquote(self.path)
113113

114114
if self._parts.scheme != "file":
115-
raise InvalidUriError(f"Invalid URI scheme '{str(self)}'.")
115+
raise InvalidUriError(f"Invalid URI scheme '{self!s}'.")
116116

117117
if netloc and self._parts.scheme == "file":
118118
# unc path: file://shares/c$/far/boo

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __str__(self) -> str:
8181
return self.pattern
8282

8383
def __repr__(self) -> str:
84-
return f"{type(self).__qualname__}(pattern={repr(self.pattern)}"
84+
return f"{type(self).__qualname__}(pattern={self.pattern!r}"
8585

8686

8787
def globmatches(pattern: str, path: Union[Path, str, os.PathLike[Any]]) -> bool:

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ def __init__(
164164
self.stack_frames: Deque[StackFrameEntry] = deque()
165165

166166
def __repr__(self) -> str:
167-
return (
168-
f"StackFrameEntry({repr(self.name)}, {repr(self.type)}, "
169-
f"{repr(self.source)}, {repr(self.line)}, {repr(self.column)})"
170-
)
167+
return f"StackFrameEntry({self.name!r}, {self.type!r}, {self.source!r}, {self.line!r}, {self.column!r})"
171168

172169
def get_first_or_self(self) -> StackFrameEntry:
173170
if self.stack_frames:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _handle_body(self, body: bytes, charset: str) -> None:
136136
except BaseException as e:
137137
self._logger.exception(e)
138138
self.send_error(
139-
f"Invalid Message: {type(e).__name__}: {str(e)} -> {str(body)}\n{traceback.format_exc()}",
139+
f"Invalid Message: {type(e).__name__}: {e!s} -> {body!s}\n{traceback.format_exc()}",
140140
error_message=Message(traceback.format_exc()),
141141
)
142142

@@ -244,7 +244,7 @@ def done(t: asyncio.Task[Any]) -> None:
244244
try:
245245
self.send_response(message.seq, message.command, t.result())
246246
except asyncio.CancelledError:
247-
self._logger.debug(lambda: f"request message {repr(message)} canceled")
247+
self._logger.debug(lambda: f"request message {message!r} canceled")
248248
except (SystemExit, KeyboardInterrupt):
249249
raise
250250
except DebugAdapterRPCErrorException as ex:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def set_result(f: asyncio.Future[Any], r: Any, ev: threading.Event) -> None:
610610
await asyncio.sleep(0)
611611

612612
else:
613-
self.__logger.warning(lambda: f"Response {repr(entry)} loop is not running.")
613+
self.__logger.warning(lambda: f"Response {entry!r} loop is not running.")
614614

615615
except (SystemExit, KeyboardInterrupt):
616616
raise
@@ -726,7 +726,7 @@ def done(t: asyncio.Future[Any]) -> None:
726726

727727
self.send_response(message.id, t.result())
728728
except asyncio.CancelledError:
729-
self.__logger.debug(lambda: f"request message {repr(message)} canceled")
729+
self.__logger.debug(lambda: f"request message {message!r} canceled")
730730
self.send_error(JsonRPCErrors.REQUEST_CANCELLED, "Request canceled.", id=message.id)
731731
except (SystemExit, KeyboardInterrupt):
732732
raise

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
@@ -154,7 +154,7 @@ async def get_or_open_document(
154154
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
155155
raise
156156
except BaseException as e:
157-
raise CantReadDocumentError(f"Error reading document '{path}': {str(e)}") from e
157+
raise CantReadDocumentError(f"Error reading document '{path}': {e!s}") from e
158158

159159
@async_event
160160
async def on_read_document_text(sender, uri: Uri) -> Optional[str]: # NOSONAR

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __str__(self) -> str:
116116
return self.id
117117

118118
def __repr__(self) -> str:
119-
return f"{type(self).__qualname__}(id={repr(self.id)}, watchers={repr(self.watchers)})"
119+
return f"{type(self).__qualname__}(id={self.id!r}, watchers={self.watchers!r})"
120120

121121

122122
class WorkspaceFolder:

0 commit comments

Comments
 (0)