Skip to content

Commit 6dbcff6

Browse files
committed
Some ruff fixes
1 parent ee7dabe commit 6dbcff6

12 files changed

Lines changed: 34 additions & 17 deletions

File tree

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
here = Path(__file__).parent.resolve()
7777
version_py = Path(here) / os.pardir / "ipykernel" / "_version.py"
7878
with open(version_py) as f:
79-
exec(compile(f.read(), version_py, "exec"), version_ns)
79+
exec(compile(f.read(), version_py, "exec"), version_ns) # noqa: S102
8080

8181
# The short X.Y version.
8282
version = "%i.%i" % version_ns["version_info"][:2]

ipykernel/connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def connect_qtconsole(
116116

117117
cf = _find_connection_file(connection_file)
118118

119-
cmd = ";".join(["from qtconsole import qtconsoleapp", "qtconsoleapp.main()"])
119+
cmd = "from qtconsole import qtconsoleapp; qtconsoleapp.main()"
120120

121121
kwargs: dict[str, Any] = {}
122122
# Launch the Qt console in a separate session & process group, so

ipykernel/debugger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
if e.__class__.__name__ == "DebuggerInitializationError":
4040
_is_debugpy_available = False
4141
else:
42-
raise e
42+
raise
4343

4444

4545
# Required for backwards compatibility
@@ -466,7 +466,7 @@ async def dumpCell(self, message):
466466
code = message["arguments"]["code"]
467467
file_name = get_file_name(code)
468468

469-
with open(file_name, "w", encoding="utf-8") as f:
469+
with open(file_name, "w", encoding="utf-8") as f: # noqa: ASYNC230
470470
f.write(code)
471471

472472
return {
@@ -496,7 +496,7 @@ async def source(self, message):
496496
reply = {"type": "response", "request_seq": message["seq"], "command": message["command"]}
497497
source_path = message["arguments"]["source"]["path"]
498498
if Path(source_path).is_file():
499-
with open(source_path, encoding="utf-8") as f:
499+
with open(source_path, encoding="utf-8") as f: # noqa: ASYNC230
500500
reply["success"] = True
501501
reply["body"] = {"content": f.read()}
502502
else:

ipykernel/inprocess/ipkernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _input_request(self, prompt, ident, parent, password=False):
107107
frontend.stdin_channel.call_handlers(msg)
108108
break
109109
else:
110-
logging.error("No frontend found for raw_input request")
110+
logging.error("No frontend found for raw_input request") # noqa: LOG015
111111
return ""
112112

113113
# Await a response.

ipykernel/ipkernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
691691
working.update(ns)
692692
code = f"{resultname} = {fname}(*{argname},**{kwargname})"
693693
try:
694-
exec(code, shell.user_global_ns, shell.user_ns)
694+
exec(code, shell.user_global_ns, shell.user_ns) # noqa: S102
695695
result = working.get(resultname)
696696
finally:
697697
for key in ns:

ipykernel/jsonutil.py

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

2727
# holy crap, strptime is not threadsafe.
2828
# Calling it once at import seems to help.
29-
datetime.strptime("2000-01-01", "%Y-%m-%d")
29+
datetime.strptime("2000-01-01", "%Y-%m-%d") # noqa: DTZ007
3030

3131
# -----------------------------------------------------------------------------
3232
# Classes and functions

ipykernel/kernelapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def init_pdb(self):
698698
With the non-interruptible version, stopping pdb() locks up the kernel in a
699699
non-recoverable state.
700700
"""
701-
import pdb
701+
import pdb # noqa: T100
702702

703703
from IPython.core import debugger
704704

ipykernel/kernelbase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ async def execute_request(self, stream, ident, parent):
860860
# clients... This seems to mitigate the problem, but we definitely need
861861
# to better understand what's going on.
862862
if self._execute_sleep:
863-
time.sleep(self._execute_sleep)
863+
time.sleep(self._execute_sleep) # noqa: ASYNC251
864864

865865
# Send the reply.
866866
reply_content = json_clean(reply_content)
@@ -1547,8 +1547,8 @@ async def _at_shutdown(self):
15471547
"""Actions taken at shutdown by the kernel, called by python's atexit."""
15481548
try:
15491549
await self._progressively_terminate_all_children()
1550-
except Exception as e:
1551-
self.log.exception("Exception during subprocesses termination %s", e)
1550+
except Exception:
1551+
self.log.exception("Exception during subprocesses termination")
15521552

15531553
finally:
15541554
if self._shutdown_message is not None and self.session:

ipykernel/trio_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ def interrupt(self, signum, frame):
3535
self._cell_cancel_scope.cancel()
3636
else:
3737
msg = "Kernel interrupted but no cell is running"
38-
raise Exception(msg)
38+
raise Exception(msg) # noqa: TRY002
3939

4040
def run(self):
4141
"""Run the loop."""
4242
old_sig = signal.signal(signal.SIGINT, self.interrupt)
4343

4444
def log_nursery_exc(exc):
4545
exc = "\n".join(traceback.format_exception(type(exc), exc, exc.__traceback__))
46-
logging.error("An exception occurred in a global nursery task.\n%s", exc)
46+
logging.error("An exception occurred in a global nursery task.\n%s", exc) # noqa: LOG015
4747

4848
async def trio_main():
4949
"""Run the main loop."""

pyproject.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,24 @@ ignore = [
271271
# PLC1901 `stderr == ""` can be simplified to `not stderr` as an empty string is falsey
272272
# B018 Found useless expression. Either assign it to a variable or remove it.
273273
# S603 `subprocess` call: check for execution of untrusted input
274-
"tests/*" = ["B011", "C408", "T201", "B007", "EM", "PTH", "PLW", "PLC1901", "B018", "S603", "ARG", "RET", "PGH"]
274+
"tests/*" = [
275+
"ARG",
276+
"B007",
277+
"B011",
278+
"B018",
279+
"BLE001",
280+
"C408",
281+
"DTZ001",
282+
"EM",
283+
"FLY002",
284+
"PGH",
285+
"PLC1901",
286+
"PLW",
287+
"PTH",
288+
"RET",
289+
"S603",
290+
"T201",
291+
]
275292
"*/__init__.py" = ["F401"]
276293

277294
[tool.interrogate]

0 commit comments

Comments
 (0)