Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ipykernel/inprocess/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"]
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/tests/test_zmq_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 9 additions & 5 deletions ipykernel/zmqshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down