From a2a4c6e020a7f6886e3ebb4e7c20370dd4070722 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:30:48 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ipykernel/kernelapp.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index 44e3bafa..c7a1d193 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -506,13 +506,13 @@ def init_io(self): if hasattr(sys.stderr, "_original_stdstream_copy"): for handler in self.log.handlers: - if (isinstance(handler, StreamHandler) - and (buffer := getattr(handler.stream, "buffer")) - and (fileno := getattr(buffer, "fileno")) - and fileno() == sys.stderr._original_stdstream_fd): - self.log.debug( - "Seeing logger to stderr, rerouting to raw filedescriptor." - ) + if ( + isinstance(handler, StreamHandler) + and (buffer := handler.stream.buffer) + and (fileno := buffer.fileno) + and fileno() == sys.stderr._original_stdstream_fd + ): + self.log.debug("Seeing logger to stderr, rerouting to raw filedescriptor.") handler.stream = TextIOWrapper( FileIO( @@ -534,18 +534,17 @@ def reset_io(self): """ stdout, stderr, displayhook = sys.stdout, sys.stderr, sys.displayhook sys.stdout, sys.stderr, sys.displayhook = self._original_io - if (finish_displayhook := getattr(displayhook, "finish_displayhook", - None)): + if finish_displayhook := getattr(displayhook, "finish_displayhook", None): finish_displayhook() if hasattr(sys.stderr, "_original_stdstream_copy"): for handler in self.log.handlers: - if (isinstance(handler, StreamHandler) - and (buffer := getattr(handler.stream, "buffer")) - and (fileno := getattr(buffer, "fileno")) - and fileno() == sys.stderr._original_stdstream_copy): - self.log.debug( - "Seeing logger to raw filedescriptor, rerouting back to stderr" - ) + if ( + isinstance(handler, StreamHandler) + and (buffer := handler.stream.buffer) + and (fileno := buffer.fileno) + and fileno() == sys.stderr._original_stdstream_copy + ): + self.log.debug("Seeing logger to raw filedescriptor, rerouting back to stderr") handler.stream = TextIOWrapper( FileIO(