Skip to content

Commit f0dbd63

Browse files
committed
chore: correct some ruff and mypy warnings
1 parent a0a7c1c commit f0dbd63

File tree

16 files changed

+70
-42
lines changed

16 files changed

+70
-42
lines changed

pyproject.toml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ dependencies = [
9191
"semantic-version",
9292
"robotremoteserver",
9393
]
94-
features = ["yaml", "rest"]
94+
features = ["yaml", "rest", "lint", "tidy"]
9595

9696

9797
[tool.hatch.envs.default.scripts]
@@ -102,6 +102,7 @@ test = "pytest {args}"
102102

103103
[tool.hatch.envs.devel]
104104
python = "38"
105+
features = ["yaml", "rest", "lint", "tidy"]
105106

106107
[[tool.hatch.envs.devel.matrix]]
107108
python = ["38", "39", "310", "311"]
@@ -140,7 +141,7 @@ matrix.rf.dependencies = [
140141

141142
[tool.hatch.envs.lint]
142143
skip-install = true
143-
features = ["yaml", "rest"]
144+
features = ["yaml", "rest", "lint", "tidy"]
144145

145146
[tool.hatch.envs.lint.scripts]
146147
typing = "mypy --install-types --non-interactive {args:.}"
@@ -229,7 +230,7 @@ exclude = [
229230
"venv",
230231
".hatch",
231232
]
232-
ignore = ["E741", "N805"]
233+
ignore = ["E741", "N805", "N999"]
233234
select = [
234235
"E",
235236
"F",
@@ -256,10 +257,18 @@ select = [
256257
"Q",
257258
"RET",
258259
# "SIM", # TODO enable this
259-
#"TID",
260-
#"TCH",
261-
#"ARG",
262-
#"PTH", # TODO enable this
260+
# "TID",
261+
# "TCH",
262+
# "ARG",
263+
# "PTH", # TODO enable this
264+
# "SLF", # TODO enable this
265+
# "ERA", # TODO enable this
266+
"RSE",
267+
# "PL",
268+
#"TRY",
269+
"RUF",
270+
# "TID"
271+
263272
]
264273

265274

@@ -301,3 +310,22 @@ module = [
301310
"pytest_regtest.*",
302311
]
303312
ignore_missing_imports = true
313+
314+
315+
[tool.hatch.build.targets.wheel.hooks.mypyc]
316+
enable-by-default = false
317+
dependencies = ["hatch-mypyc", "types-PyYAML", "types-docutils"]
318+
require-runtime-dependencies = true
319+
include = [
320+
"robotcode/utils/glob_path.py",
321+
"robotcode/language_server/robotframework/diagnostics/analyzer.py",
322+
]
323+
exclude = ["__main__.py", "__version__.py", "__init__.py", "typings", "tests"]
324+
325+
326+
[tool.hatch.build.targets.wheel.hooks.mypyc.options]
327+
# # opt_level = "3"
328+
# multi_file = true
329+
#separate = true
330+
#verbose = true
331+
#include_runtime_files = false

robotcode/debugger/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def main() -> None:
344344
split_index = sys_args.index("--") if "--" in sys_args else -1
345345

346346
my_args = sys_args[:split_index] if split_index >= 0 else sys_args
347-
robot_args = sys_args[split_index + 1 :] if split_index >= 0 else [] # noqa: E203
347+
robot_args = sys_args[split_index + 1 :] if split_index >= 0 else []
348348

349349
args = parser.parse_args(my_args)
350350

robotcode/debugger/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,4 @@ def handle_response(self, message: Response) -> None:
360360

361361
@_logger.call
362362
def handle_event(self, message: Event) -> None:
363-
raise NotImplementedError()
363+
raise NotImplementedError

robotcode/jsonrpc2/protocol.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class HasRpcRegistry(Protocol):
208208

209209

210210
class RpcRegistry:
211-
_class_registries: ClassVar[Dict[Type[Any], RpcRegistry]] = {}
211+
class_registries: ClassVar[Dict[Type[Any], RpcRegistry]] = {}
212212

213213
def __init__(self, owner: Any = None) -> None:
214214
self.__owner = owner
@@ -230,10 +230,10 @@ def __get__(self, obj: Any, obj_type: Type[Any]) -> "RpcRegistry":
230230

231231
return cast(HasRpcRegistry, obj).__rpc_registry__
232232

233-
if obj_type not in RpcRegistry._class_registries:
234-
RpcRegistry._class_registries[obj_type] = RpcRegistry(obj_type)
233+
if obj_type not in RpcRegistry.class_registries:
234+
RpcRegistry.class_registries[obj_type] = RpcRegistry(obj_type)
235235

236-
return RpcRegistry._class_registries[obj_type]
236+
return RpcRegistry.class_registries[obj_type]
237237

238238
def _reset(self) -> None:
239239
self.__methods.clear()
@@ -277,7 +277,7 @@ def get_methods(obj: Any) -> Dict[str, RpcMethodEntry]:
277277
else:
278278
registries: List[RpcRegistry] = []
279279
for m in inspect.getmro(type(self.__owner)):
280-
r = RpcRegistry._class_registries.get(m, None)
280+
r = RpcRegistry.class_registries.get(m, None)
281281
if r is not None:
282282
registries.insert(0, r)
283283
for r in registries:
@@ -815,7 +815,7 @@ def __init__(self, instance_type: Type[TProtocolPart], *args: Any, **kwargs: Any
815815

816816
def __set_name__(self, owner: Type[Any], name: str) -> None:
817817
if not issubclass(owner, JsonRPCProtocol):
818-
raise AttributeError()
818+
raise TypeError
819819
owner.registry.add_class_part(name, self._instance_type)
820820

821821
def __get__(self, obj: Optional[Any], objtype: Type[Any]) -> TProtocolPart:

robotcode/jsonrpc2/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ def start_pipe(self, pipe_name: Optional[str]) -> None:
227227
)
228228
else:
229229
self.loop.run_until_complete(self.loop.create_unix_connection(self.create_protocol, pipe_name))
230-
except NotImplementedError:
231-
raise NotSupportedError("Pipe transport is not supported on this platform.")
230+
except NotImplementedError as e:
231+
raise NotSupportedError("Pipe transport is not supported on this platform.") from e
232232

233233
self._run_func = self.loop.run_forever
234234

robotcode/language_server/common/parts/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _cancel_all_tasks(loop: asyncio.AbstractEventLoop) -> None:
9494
for task in to_cancel:
9595
task.cancel()
9696

97-
loop.run_until_complete(asyncio.gather(*to_cancel, loop=loop, return_exceptions=True))
97+
loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True))
9898

9999
for task in to_cancel:
100100
if task.cancelled():

robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def __getitem__(self, key: str) -> "KeywordDoc":
540540
items = [(k, v) for k, v in self._matchers.items() if k == key]
541541

542542
if not items:
543-
raise KeyError()
543+
raise KeyError
544544
if len(items) == 1:
545545
return items[0][1]
546546

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,12 +1749,12 @@ def _find_keyword(self, name: Optional[str]) -> Optional[KeywordDoc]:
17491749
self.diagnostics.append(
17501750
DiagnosticsEntry("Keyword name cannot be empty.", DiagnosticSeverity.ERROR, "KeywordError")
17511751
)
1752-
raise CancelSearchError()
1752+
raise CancelSearchError
17531753
if not isinstance(name, str):
17541754
self.diagnostics.append( # type: ignore
17551755
DiagnosticsEntry("Keyword name must be a string.", DiagnosticSeverity.ERROR, "KeywordError")
17561756
)
1757-
raise CancelSearchError()
1757+
raise CancelSearchError
17581758

17591759
result = self._get_keyword_from_self(name)
17601760
if not result and "." in name:
@@ -1783,7 +1783,7 @@ def _get_keyword_from_self(self, name: str) -> Optional[KeywordDoc]:
17831783
"KeywordError",
17841784
)
17851785
)
1786-
raise CancelSearchError()
1786+
raise CancelSearchError
17871787

17881788
if len(found) == 1:
17891789
# TODO warning if keyword found is defined in resource and suite
@@ -1801,7 +1801,7 @@ def _get_keyword_from_self(self, name: str) -> Optional[KeywordDoc]:
18011801
"KeywordError",
18021802
)
18031803
)
1804-
raise CancelSearchError() from e
1804+
raise CancelSearchError from e
18051805

18061806
def _yield_owner_and_kw_names(self, full_name: str) -> Iterator[Tuple[str, ...]]:
18071807
tokens = full_name.split(".")
@@ -1824,7 +1824,7 @@ def _get_explicit_keyword(self, name: str) -> Optional[KeywordDoc]:
18241824
"KeywordError",
18251825
)
18261826
)
1827-
raise CancelSearchError()
1827+
raise CancelSearchError
18281828

18291829
return found[0][1] if found else None
18301830

@@ -1859,7 +1859,7 @@ def _create_multiple_keywords_found_message(
18591859
error += ". Give the full name of the keyword you want to use"
18601860

18611861
names = sorted(f"{e[1].name if e[0] is None else f'{e[0].alias or e[0].name}.{e[1].name}'}" for e in found)
1862-
return "\n ".join([error + ":"] + names)
1862+
return "\n ".join([f"{error}:", *names])
18631863

18641864
def _get_implicit_keyword(self, name: str) -> Optional[KeywordDoc]:
18651865
result = self._get_keyword_from_resource_files(name)
@@ -1954,7 +1954,7 @@ def _get_keyword_from_resource_files(self, name: str) -> Optional[KeywordDoc]:
19541954
"KeywordError",
19551955
)
19561956
)
1957-
raise CancelSearchError()
1957+
raise CancelSearchError
19581958

19591959
def _get_keyword_based_on_search_order(
19601960
self, entries: List[Tuple[Optional[LibraryEntry], KeywordDoc]]
@@ -2008,7 +2008,7 @@ def _get_keyword_from_libraries(self, name: str) -> Optional[KeywordDoc]:
20082008
"KeywordError",
20092009
)
20102010
)
2011-
raise CancelSearchError()
2011+
raise CancelSearchError
20122012

20132013
def _filter_stdlib_runner(
20142014
self, entry1: Tuple[Optional[LibraryEntry], KeywordDoc], entry2: Tuple[Optional[LibraryEntry], KeywordDoc]
@@ -2056,7 +2056,7 @@ def _get_bdd_style_keyword(self, name: str) -> Optional[KeywordDoc]:
20562056
lower = name.lower()
20572057
for prefix in ["given ", "when ", "then ", "and ", "but "]:
20582058
if lower.startswith(prefix):
2059-
return self._find_keyword(name[len(prefix) :]) # noqa: E203
2059+
return self._find_keyword(name[len(prefix) :])
20602060
return None
20612061

20622062
parts = name.split()

robotcode/language_server/robotframework/parts/code_action_documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async def collect(
320320

321321
if isinstance(node, KeywordName):
322322
name_token = node.get_token(RobotToken.KEYWORD_NAME)
323-
if name_token and range in range_from_token(name_token):
323+
if name_token is not None and range in range_from_token(name_token):
324324
url = await self.build_url(str(document.uri.to_path().name), (), document, namespace, name_token.value)
325325

326326
return [self.open_documentation_code_action(url)]

robotcode/language_server/robotframework/parts/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def enumerate_indexes(s: str, c: str) -> Iterator[int]:
699699
lib_name_index = e
700700

701701
if lib_name_index >= 0:
702-
library_name = token.value[0 : lib_name_index - r.start.character] # noqa: E203
702+
library_name = token.value[0 : lib_name_index - r.start.character]
703703

704704
libraries = await self.namespace.get_libraries()
705705

0 commit comments

Comments
 (0)