From b9fd34305b1b2b5a35726ff2fd7da011d095fd66 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 3 Jan 2023 09:20:36 -0600 Subject: [PATCH] fix types and sync lint deps --- ipykernel/inprocess/tests/test_kernel.py | 2 +- ipykernel/ipkernel.py | 2 +- ipykernel/kernelapp.py | 22 +++++++++++----------- ipykernel/tests/test_kernel.py | 2 +- ipykernel/tests/test_zmq_shell.py | 2 +- ipykernel/zmqshell.py | 14 +++++++++----- pyproject.toml | 2 +- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ipykernel/inprocess/tests/test_kernel.py b/ipykernel/inprocess/tests/test_kernel.py index 947b5823e..defe039df 100644 --- a/ipykernel/inprocess/tests/test_kernel.py +++ b/ipykernel/inprocess/tests/test_kernel.py @@ -6,7 +6,7 @@ from io import StringIO import pytest -from IPython.utils.io import capture_output +from IPython.utils.io import capture_output # type:ignore[attr-defined] from jupyter_client.session import Session from ipykernel.inprocess.blocking import BlockingInProcessKernelClient diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index f4b67caa2..a4b975a4b 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -26,7 +26,7 @@ from .zmqshell import ZMQInteractiveShell try: - from IPython.core.interactiveshell import _asyncio_runner + from IPython.core.interactiveshell import _asyncio_runner # type:ignore[attr-defined] except ImportError: _asyncio_runner = None diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index 24355b14b..a98439cfc 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -15,7 +15,7 @@ from logging import StreamHandler import zmq -from IPython.core.application import ( +from IPython.core.application import ( # type:ignore[attr-defined] BaseIPythonApplication, base_aliases, base_flags, @@ -88,12 +88,12 @@ ) # inherit flags&aliases for any IPython shell apps -kernel_aliases.update(shell_aliases) +kernel_aliases.update(shell_aliases) # type:ignore[arg-type] kernel_flags.update(shell_flags) # inherit flags&aliases for Sessions -kernel_aliases.update(session_aliases) -kernel_flags.update(session_flags) +kernel_aliases.update(session_aliases) # type:ignore[arg-type] +kernel_flags.update(session_flags) # type:ignore[arg-type] _ctrl_c_message = """\ NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work. @@ -114,8 +114,8 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix """The IPYKernel application class.""" name = "ipython-kernel" - aliases = Dict(kernel_aliases) - flags = Dict(kernel_flags) + aliases = Dict(kernel_aliases) # type:ignore[assignment] + flags = Dict(kernel_flags) # type:ignore[assignment] classes = [IPythonKernel, ZMQInteractiveShell, ProfileDir, Session] # the kernel class, as an importstring kernel_class = Type( @@ -429,7 +429,7 @@ def log_connection_info(self): self.log.info(line) # also raw print to the terminal if no parent_handle (`ipython kernel`) # unless log-level is CRITICAL (--quiet) - if not self.parent_handle and self.log_level < logging.CRITICAL: + if not self.parent_handle and int(self.log_level) < logging.CRITICAL: print(_ctrl_c_message, file=sys.__stdout__) for line in lines: print(line, file=sys.__stdout__) @@ -658,9 +658,9 @@ def init_pdb(self): if hasattr(debugger, "InterruptiblePdb"): # Only available in newer IPython releases: - debugger.Pdb = debugger.InterruptiblePdb - pdb.Pdb = debugger.Pdb # type:ignore[misc] - pdb.set_trace = debugger.set_trace + debugger.Pdb = debugger.InterruptiblePdb # type:ignore + pdb.Pdb = debugger.Pdb # type:ignore + pdb.set_trace = debugger.set_trace # type:ignore[assignment] @catch_config_error def initialize(self, argv=None): @@ -687,7 +687,7 @@ def initialize(self, argv=None): except Exception: # Catch exception when initializing signal fails, eg when running the # kernel on a separate thread - if self.log_level < logging.CRITICAL: + if int(self.log_level) < logging.CRITICAL: self.log.error("Unable to initialize signal:", exc_info=True) self.init_kernel() # shell init steps diff --git a/ipykernel/tests/test_kernel.py b/ipykernel/tests/test_kernel.py index 0647ef442..b48d51967 100644 --- a/ipykernel/tests/test_kernel.py +++ b/ipykernel/tests/test_kernel.py @@ -517,7 +517,7 @@ def _print_and_exit(sig, frame): def _start_children(): - ip = IPython.get_ipython() + ip = IPython.get_ipython() # type:ignore[attr-defined] ns = ip.user_ns cmd = [sys.executable, "-c", f"from {__name__} import _child; _child()"] diff --git a/ipykernel/tests/test_zmq_shell.py b/ipykernel/tests/test_zmq_shell.py index 52e11e43a..665139271 100644 --- a/ipykernel/tests/test_zmq_shell.py +++ b/ipykernel/tests/test_zmq_shell.py @@ -238,7 +238,7 @@ def test_zmq_interactive_shell(kernel): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) - shell.data_pub_class = MagicMock() + shell.data_pub_class = MagicMock() # type:ignore shell.data_pub shell.kernel = kernel shell.set_next_input("hi") diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 2d08c1136..f36baf5f7 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -25,11 +25,11 @@ from IPython.core.error import UsageError from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.core.magic import Magics, line_magic, magics_class -from IPython.core.magics import CodeMagics, MacroToEdit +from IPython.core.magics import CodeMagics, MacroToEdit # type:ignore[attr-defined] from IPython.core.usage import default_banner -from IPython.display import Javascript, display +from IPython.display import Javascript, display # type:ignore[attr-defined] from IPython.utils import openpy -from IPython.utils.process import arg_split, system +from IPython.utils.process import arg_split, system # type:ignore[attr-defined] from jupyter_client.session import Session, extract_header from jupyter_core.paths import jupyter_runtime_dir from traitlets import Any, CBool, CBytes, Dict, Instance, Type, default, observe @@ -296,6 +296,7 @@ def edit(self, parameter_s="", last_call=None): filename = os.path.abspath(filename) payload = {"source": "edit_magic", "filename": filename, "line_number": lineno} + assert self.shell is not None self.shell.payload_manager.write_payload(payload) # A few magics that are adapted to the specifics of using pexpect and a @@ -304,6 +305,7 @@ def edit(self, parameter_s="", last_call=None): @line_magic def clear(self, arg_s): """Clear the terminal.""" + assert self.shell is not None if os.name == "posix": self.shell.system("clear") else: @@ -324,6 +326,7 @@ def less(self, arg_s): raise UsageError("Missing filename.") if arg_s.endswith(".py"): + assert self.shell is not None cont = self.shell.pycolorize(openpy.read_py_file(arg_s, skip_encoding_cookie=False)) else: with open(arg_s) as fid: @@ -338,6 +341,7 @@ def less(self, arg_s): @line_magic def man(self, arg_s): """Find the man page for the given command and display in pager.""" + assert self.shell is not None page.page(self.shell.getoutput("man %s | col -b" % arg_s, split=False)) @line_magic @@ -430,7 +434,7 @@ class ZMQInteractiveShell(InteractiveShell): displayhook_class = Type(ZMQShellDisplayHook) display_pub_class = Type(ZMQDisplayPublisher) - data_pub_class = Any() + data_pub_class = Any() # type:ignore[assignment] kernel = Any() parent_header = Any() @@ -511,7 +515,7 @@ def data_pub(self): stacklevel=2, ) - self._data_pub = self.data_pub_class(parent=self) + self._data_pub = self.data_pub_class(parent=self) # type:ignore[has-type] self._data_pub.session = self.display_pub.session self._data_pub.pub_socket = self.display_pub.pub_socket return self._data_pub diff --git a/pyproject.toml b/pyproject.toml index b8c79fbad..77b885ecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,7 +111,7 @@ dependencies = ["mypy>=0.990"] test = "mypy --install-types --non-interactive {args:.}" [tool.hatch.envs.lint] -dependencies = ["black==22.10.0", "mdformat>0.7", "ruff==0.0.189"] +dependencies = ["black==22.12.0", "mdformat>0.7", "ruff==0.0.207"] detached = true [tool.hatch.envs.lint.scripts] style = [