diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9aa4daacc..a87ce7f17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.37.4 + rev: 0.38.0 hooks: - id: check-github-workflows @@ -95,7 +95,7 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.22 + rev: v0.16.2 hooks: - id: ruff-check types_or: [python, jupyter] diff --git a/docs/conf.py b/docs/conf.py index 7ab188f4b..3976acb1c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -76,7 +76,7 @@ here = Path(__file__).parent.resolve() version_py = Path(here) / os.pardir / "ipykernel" / "_version.py" with open(version_py) as f: - exec(compile(f.read(), version_py, "exec"), version_ns) + exec(compile(f.read(), version_py, "exec"), version_ns) # noqa: S102 # The short X.Y version. version = "%i.%i" % version_ns["version_info"][:2] diff --git a/ipykernel/__init__.py b/ipykernel/__init__.py index 978700d30..bc5fbb726 100644 --- a/ipykernel/__init__.py +++ b/ipykernel/__init__.py @@ -4,4 +4,4 @@ kernel_protocol_version_info, version_info, ) -from .connect import * # noqa: F403 +from .connect import * diff --git a/ipykernel/compiler.py b/ipykernel/compiler.py index 6652e08ae..254642109 100644 --- a/ipykernel/compiler.py +++ b/ipykernel/compiler.py @@ -46,7 +46,7 @@ def murmur2_x86(data, seed): return h -convert_to_long_pathname = lambda filename: filename # noqa: E731 +convert_to_long_pathname = lambda filename: filename if sys.platform == "win32": try: @@ -66,7 +66,7 @@ def _convert_to_long_pathname(filename): # test that it works so if there are any issues we fail just once here _convert_to_long_pathname(__file__) - except Exception: + except Exception: # noqa: S110 pass else: convert_to_long_pathname = _convert_to_long_pathname diff --git a/ipykernel/connect.py b/ipykernel/connect.py index 1e1f16cdc..e93ffb90e 100644 --- a/ipykernel/connect.py +++ b/ipykernel/connect.py @@ -116,7 +116,7 @@ def connect_qtconsole( cf = _find_connection_file(connection_file) - cmd = ";".join(["from qtconsole import qtconsoleapp", "qtconsoleapp.main()"]) + cmd = "from qtconsole import qtconsoleapp; qtconsoleapp.main()" kwargs: dict[str, Any] = {} # Launch the Qt console in a separate session & process group, so diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py index db04eae6f..6bcb59114 100644 --- a/ipykernel/debugger.py +++ b/ipykernel/debugger.py @@ -39,7 +39,7 @@ if e.__class__.__name__ == "DebuggerInitializationError": _is_debugpy_available = False else: - raise e + raise if t.TYPE_CHECKING: from IPython.core.interactiveshell import InteractiveShell @@ -470,7 +470,7 @@ async def dumpCell(self, message): code = message["arguments"]["code"] file_name = get_file_name(code) - with open(file_name, "w", encoding="utf-8") as f: + with open(file_name, "w", encoding="utf-8") as f: # noqa: ASYNC230 f.write(code) return { @@ -500,7 +500,7 @@ async def source(self, message): reply = {"type": "response", "request_seq": message["seq"], "command": message["command"]} source_path = message["arguments"]["source"]["path"] if Path(source_path).is_file(): - with open(source_path, encoding="utf-8") as f: + with open(source_path, encoding="utf-8") as f: # noqa: ASYNC230 reply["success"] = True reply["body"] = {"content": f.read()} else: diff --git a/ipykernel/eventloops.py b/ipykernel/eventloops.py index dd160674a..69965ca71 100644 --- a/ipykernel/eventloops.py +++ b/ipykernel/eventloops.py @@ -207,7 +207,7 @@ def wake(self): try: if self.shell_stream.flush(limit=1): self.kernel.app.ExitMainLoop() - except Exception: + except Exception: # noqa: S110 pass def on_timer(self, event): @@ -409,7 +409,7 @@ def handle_int(etype, value, tb): if shell_stream.flush(limit=1): # events to process, return control to kernel return - except BaseException: + except BaseException: # noqa: TRY203 raise except KeyboardInterrupt: # Ctrl-C shouldn't crash the kernel diff --git a/ipykernel/gui/gtk3embed.py b/ipykernel/gui/gtk3embed.py index ab4ec2226..91b5b4942 100644 --- a/ipykernel/gui/gtk3embed.py +++ b/ipykernel/gui/gtk3embed.py @@ -18,7 +18,7 @@ gi.require_version("Gdk", "3.0") gi.require_version("Gtk", "3.0") -from gi.repository import GObject, Gtk # noqa: E402 +from gi.repository import GObject, Gtk warnings.warn( "The Gtk3 event loop for ipykernel is deprecated", category=DeprecationWarning, stacklevel=2 diff --git a/ipykernel/inprocess/ipkernel.py b/ipykernel/inprocess/ipkernel.py index e61af4277..ebefd16e1 100644 --- a/ipykernel/inprocess/ipkernel.py +++ b/ipykernel/inprocess/ipkernel.py @@ -107,7 +107,7 @@ def _input_request(self, prompt, ident, parent, password=False): frontend.stdin_channel.call_handlers(msg) break else: - logging.error("No frontend found for raw_input request") + logging.error("No frontend found for raw_input request") # noqa: LOG015 return "" # Await a response. diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index a5b5b6c0b..8962d3e53 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -318,7 +318,7 @@ def stop(self): # close *all* event pipes, created in any thread # event pipes can only be used from other threads while self.thread.is_alive() # so after thread.join, this should be safe - for _thread, event_pipe in self._event_pipes.items(): + for event_pipe in self._event_pipes.values(): event_pipe.close() def close(self): diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index 7ce9cc013..71b387fab 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -394,7 +394,7 @@ async def do_execute( should_run_async = shell.should_run_async accepts_params = _accepts_parameters(run_cell, ["cell_id", "cell_meta"]) else: - should_run_async = lambda cell: False # noqa: ARG005, E731 + should_run_async = lambda cell: False # noqa: ARG005 # older IPython, # use blocking run_cell and wrap it in coroutine @@ -691,7 +691,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata): working.update(ns) code = f"{resultname} = {fname}(*{argname},**{kwargname})" try: - exec(code, shell.user_global_ns, shell.user_ns) + exec(code, shell.user_global_ns, shell.user_ns) # noqa: S102 result = working.get(resultname) finally: for key in ns: diff --git a/ipykernel/jsonutil.py b/ipykernel/jsonutil.py index d40661c74..57e975c0f 100644 --- a/ipykernel/jsonutil.py +++ b/ipykernel/jsonutil.py @@ -26,7 +26,7 @@ # holy crap, strptime is not threadsafe. # Calling it once at import seems to help. -datetime.strptime("2000-01-01", "%Y-%m-%d") +datetime.strptime("2000-01-01", "%Y-%m-%d") # noqa: DTZ007 # ----------------------------------------------------------------------------- # Classes and functions diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index b6e8b59a1..8f5488fc5 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -698,7 +698,7 @@ def init_pdb(self): With the non-interruptible version, stopping pdb() locks up the kernel in a non-recoverable state. """ - import pdb + import pdb # noqa: T100 from IPython.core import debugger diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index 073ce01d1..fed17d69d 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -860,7 +860,7 @@ async def execute_request(self, stream, ident, parent): # clients... This seems to mitigate the problem, but we definitely need # to better understand what's going on. if self._execute_sleep: - time.sleep(self._execute_sleep) + time.sleep(self._execute_sleep) # noqa: ASYNC251 # Send the reply. reply_content = json_clean(reply_content) @@ -1559,8 +1559,8 @@ async def _at_shutdown(self): """Actions taken at shutdown by the kernel, called by python's atexit.""" try: await self._progressively_terminate_all_children() - except Exception as e: - self.log.exception("Exception during subprocesses termination %s", e) + except Exception: + self.log.exception("Exception during subprocesses termination") finally: if self._shutdown_message is not None and self.session: diff --git a/ipykernel/pylab/backend_inline.py b/ipykernel/pylab/backend_inline.py index 2ce3716b8..abc8af673 100644 --- a/ipykernel/pylab/backend_inline.py +++ b/ipykernel/pylab/backend_inline.py @@ -5,7 +5,7 @@ import warnings -from matplotlib_inline.backend_inline import * # noqa: F403 # analysis: ignore +from matplotlib_inline.backend_inline import * # analysis: ignore warnings.warn( "`ipykernel.pylab.backend_inline` is deprecated, directly " diff --git a/ipykernel/pylab/config.py b/ipykernel/pylab/config.py index 8c3a63ab4..bbe537463 100644 --- a/ipykernel/pylab/config.py +++ b/ipykernel/pylab/config.py @@ -5,7 +5,7 @@ import warnings -from matplotlib_inline.config import * # noqa: F403 # analysis: ignore +from matplotlib_inline.config import * # analysis: ignore warnings.warn( "`ipykernel.pylab.config` is deprecated, directly use `matplotlib_inline.config`", diff --git a/ipykernel/trio_runner.py b/ipykernel/trio_runner.py index 6fb44107b..fefd73034 100644 --- a/ipykernel/trio_runner.py +++ b/ipykernel/trio_runner.py @@ -35,7 +35,7 @@ def interrupt(self, signum, frame): self._cell_cancel_scope.cancel() else: msg = "Kernel interrupted but no cell is running" - raise Exception(msg) + raise Exception(msg) # noqa: TRY002 def run(self): """Run the loop.""" @@ -43,7 +43,7 @@ def run(self): def log_nursery_exc(exc): exc = "\n".join(traceback.format_exception(type(exc), exc, exc.__traceback__)) - logging.error("An exception occurred in a global nursery task.\n%s", exc) + logging.error("An exception occurred in a global nursery task.\n%s", exc) # noqa: LOG015 async def trio_main(): """Run the main loop.""" diff --git a/pyproject.toml b/pyproject.toml index e22ad0652..4075fb79f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -261,6 +261,7 @@ ignore = [ "UP031", # Use format specifiers instead of percent format "PT023", # Use `@pytest.mark.skip` over `@pytest.mark.skip()` "PT001", # autofixable: Use `@pytest.fixture` over `@pytest.fixture()` + "BLE001" # Do not catch blind exception: `Exception` ] [tool.ruff.lint.per-file-ignores] @@ -272,7 +273,24 @@ ignore = [ # PLC1901 `stderr == ""` can be simplified to `not stderr` as an empty string is falsey # B018 Found useless expression. Either assign it to a variable or remove it. # S603 `subprocess` call: check for execution of untrusted input -"tests/*" = ["B011", "C408", "T201", "B007", "EM", "PTH", "PLW", "PLC1901", "B018", "S603", "ARG", "RET", "PGH"] +"tests/*" = [ + "ARG", + "B007", + "B011", + "B018", + "BLE001", + "C408", + "DTZ001", + "EM", + "FLY002", + "PGH", + "PLC1901", + "PLW", + "PTH", + "RET", + "S603", + "T201", +] "*/__init__.py" = ["F401"] [tool.interrogate] diff --git a/tests/test_debugger.py b/tests/test_debugger.py index 90380629f..b7ec123df 100644 --- a/tests/test_debugger.py +++ b/tests/test_debugger.py @@ -11,7 +11,7 @@ # functionally as the debug message replies are usually empty dictionaries, but they confirm that # ipykernel doesn't block, or segfault, or raise an exception. try: - import debugpy + import debugpy # noqa: T100 except ImportError: debugpy = None diff --git a/tests/test_eventloop.py b/tests/test_eventloop.py index 428a7cdb7..c353542c2 100644 --- a/tests/test_eventloop.py +++ b/tests/test_eventloop.py @@ -78,7 +78,7 @@ def do_thing(): # guard for tk failing to start (if there is no display) try: loop_tk(kernel) - except Exception: + except Exception: # noqa: S110 pass t.join()