Skip to content
Open
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
8 changes: 4 additions & 4 deletions ipykernel/_eventloop_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _NSApp():
return msg(C("NSApplication"), n("sharedApplication"))


def _wake(NSApp):
def _wake(NSApp) -> None:
"""Wake the Application"""
objc.objc_msgSend.argtypes = [
void_p,
Expand Down Expand Up @@ -121,7 +121,7 @@ def _wake(NSApp):
_triggered = Event()


def stop(timer=None, loop=None):
def stop(timer=None, loop=None) -> None:
"""Callback to fire when there's input to be read"""
_triggered.set()
NSApp = _NSApp()
Expand All @@ -140,7 +140,7 @@ def stop(timer=None, loop=None):
_c_stop_callback = _c_callback_func_type(stop)


def _stop_after(delay):
def _stop_after(delay) -> None:
"""Register callback to stop eventloop after a delay"""
timer = CFRunLoopTimerCreate(
None, # allocator
Expand All @@ -158,7 +158,7 @@ def _stop_after(delay):
)


def mainloop(duration=1):
def mainloop(duration=1) -> None:
"""run the Cocoa eventloop for the specified duration (seconds)"""

_triggered.clear()
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BaseComm(comm.base_comm.BaseComm):

kernel: Optional["Kernel"] = None

def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys) -> None:
"""Helper for sending a comm message on IOPub"""
if not Kernel.initialized():
return
Expand Down Expand Up @@ -75,7 +75,7 @@ def _default_comm_id(self):

def __init__(
self, target_name="", data=None, metadata=None, buffers=None, show_warning=True, **kwargs
):
) -> None:
"""Initialize a comm."""
if show_warning:
warn(
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurab
comms = traitlets.Dict()
targets = traitlets.Dict()

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
"""Initialize the manager."""
# CommManager doesn't take arguments, so we explicitly forward arguments
comm.base_comm.CommManager.__init__(self)
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)

def comm_open(self, stream, ident, msg):
def comm_open(self, stream, ident, msg) -> None:
"""Handler for comm_open messages"""
# This is for backward compatibility, the comm_open creates a a new ipykernel.comm.Comm
# but we should let the base class create the comm with comm.create_comm in a major release
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_tmp_directory():
return tmp_dir + os.sep + "ipykernel_" + str(pid)


def get_tmp_hash_seed():
def get_tmp_hash_seed() -> int:
"""Get a temp hash seed."""
return 0xC70F6907

Expand All @@ -96,7 +96,7 @@ def get_file_name(code):
class XCachingCompiler(CachingCompiler):
"""A custom caching compiler."""

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
"""Initialize the compiler."""
super().__init__(*args, **kwargs)
self.log = None
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class ControlThread(BaseThread):
"""A thread for a control channel."""

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
"""Initialize the thread."""
super().__init__(name=CONTROL_THREAD_NAME, **kwargs)
49 changes: 27 additions & 22 deletions ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
class _FakeCode:
"""Fake code class."""

def __init__(self, co_filename, co_name):
def __init__(self, co_filename, co_name) -> None:
"""Init."""
self.co_filename = co_filename
self.co_name = co_name
Expand All @@ -60,7 +60,7 @@ def __init__(self, co_filename, co_name):
class _FakeFrame:
"""Fake frame class."""

def __init__(self, f_code, f_globals, f_locals):
def __init__(self, f_code, f_globals, f_locals) -> None:
"""Init."""
self.f_code = f_code
self.f_globals = f_globals
Expand All @@ -71,7 +71,7 @@ def __init__(self, f_code, f_globals, f_locals):
class _DummyPyDB:
"""Fake PyDb class."""

def __init__(self):
def __init__(self) -> None:
"""Init."""
from _pydevd_bundle.pydevd_api import PyDevdAPI

Expand All @@ -81,20 +81,21 @@ def __init__(self):
class VariableExplorer:
"""A variable explorer."""

def __init__(self):
frame: _FakeFrame | None = None

def __init__(self) -> None:
"""Initialize the explorer."""
self.suspended_frame_manager = SuspendedFramesManager()
self.py_db = _DummyPyDB()
self.tracker = _FramesTracker(self.suspended_frame_manager, self.py_db)
self.frame = None

def track(self):
def track(self) -> None:
"""Start tracking."""
var = t.cast("InteractiveShell", get_ipython()).user_ns
self.frame = _FakeFrame(_FakeCode("<module>", get_file_name("sys._getframe()")), var, var)
self.tracker.track("thread1", pydevd_frame_utils.create_frames_list_from_frame(self.frame))

def untrack_all(self):
def untrack_all(self) -> None:
"""Stop tracking."""
self.tracker.untrack_all()

Expand All @@ -115,21 +116,21 @@ class DebugpyMessageQueue:
SEPARATOR = "\r\n\r\n"
SEPARATOR_LENGTH = 4

def __init__(self, event_callback, log):
def __init__(self, event_callback, log) -> None:
"""Init the queue."""
self.tcp_buffer = ""
self._reset_tcp_pos()
self.event_callback = event_callback
self.message_queue: Queue[t.Any] = Queue()
self.log = log

def _reset_tcp_pos(self):
def _reset_tcp_pos(self) -> None:
self.header_pos = -1
self.separator_pos = -1
self.message_size = 0
self.message_pos = -1

def _put_message(self, raw_msg):
def _put_message(self, raw_msg) -> None:
self.log.debug("QUEUE - _put_message:")
msg = t.cast(dict[str, t.Any], jsonapi.loads(raw_msg))
if msg["type"] == "event":
Expand All @@ -141,7 +142,7 @@ def _put_message(self, raw_msg):
self.log.debug(msg)
self.message_queue.put_nowait(msg)

def put_tcp_frame(self, frame):
def put_tcp_frame(self, frame) -> None:
"""Put a tcp frame in the queue."""
self.tcp_buffer += frame

Expand Down Expand Up @@ -196,7 +197,7 @@ async def get_message(self):
class DebugpyClient:
"""A client for debugpy."""

def __init__(self, log, debugpy_stream, event_callback):
def __init__(self, log, debugpy_stream, event_callback) -> None:
"""Initialize the client."""
self.log = log
self.debugpy_stream = debugpy_stream
Expand All @@ -213,13 +214,13 @@ def _get_endpoint(self):
host, port = self.get_host_port()
return "tcp://" + host + ":" + str(port)

def _forward_event(self, msg):
def _forward_event(self, msg) -> None:
if msg["event"] == "initialized":
self.init_event.set()
self.init_event_seq = msg["seq"]
self.event_callback(msg)

def _send_request(self, msg):
def _send_request(self, msg) -> None:
if self.routing_id is None:
self.routing_id = self.debugpy_stream.socket.getsockopt(ROUTING_ID)
content = jsonapi.dumps(
Expand Down Expand Up @@ -273,20 +274,20 @@ def get_host_port(self):
self.debugpy_port = self.endpoint[index + 1 :]
return self.debugpy_host, self.debugpy_port

def connect_tcp_socket(self):
def connect_tcp_socket(self) -> None:
"""Connect to the tcp socket."""
self.debugpy_stream.socket.connect(self._get_endpoint())
self.routing_id = self.debugpy_stream.socket.getsockopt(ROUTING_ID)

def disconnect_tcp_socket(self):
def disconnect_tcp_socket(self) -> None:
"""Disconnect from the tcp socket."""
self.debugpy_stream.socket.disconnect(self._get_endpoint())
self.routing_id = None
self.init_event = Event()
self.init_event_seq = -1
self.wait_for_attach = True

def receive_dap_frame(self, frame):
def receive_dap_frame(self, frame) -> None:
"""Receive a dap frame."""
self.message_queue.put_tcp_frame(frame)

Expand All @@ -307,6 +308,10 @@ async def send_dap_request(self, msg):
class Debugger:
"""The debugger class."""

breakpoint_list: dict[str, t.Any]
stopped_threads: set[int]
_removed_cleanup: dict[int, t.Any]

# Requests that requires that the debugger has started
started_debug_msg_types = [
"dumpCell",
Expand Down Expand Up @@ -337,7 +342,7 @@ def __init__(
kernel_modules,
just_my_code=False,
filter_internal_frames=True,
):
) -> None:
"""Initialize the debugger."""
self.log = log
self.debugpy_client = DebugpyClient(log, debugpy_stream, self._handle_event)
Expand Down Expand Up @@ -370,7 +375,7 @@ def __init__(

self.variable_explorer = VariableExplorer()

def _handle_event(self, msg):
def _handle_event(self, msg) -> None:
if msg["event"] == "stopped":
if msg["body"]["allThreadsStopped"]:
self.stopped_queue.put_nowait(msg)
Expand Down Expand Up @@ -401,13 +406,13 @@ def _build_variables_response(self, request, variables):
"body": {"variables": var_list},
}

def _accept_stopped_thread(self, thread_name):
def _accept_stopped_thread(self, thread_name) -> bool:
# TODO: identify Thread-2, Thread-3 and Thread-4. These are NOT
# Control, IOPub or Heartbeat threads
forbid_list = ["IPythonHistorySavingThread", "Thread-2", "Thread-3", "Thread-4"]
return thread_name not in forbid_list

async def handle_stopped_event(self):
async def handle_stopped_event(self) -> None:
"""Handle a stopped event."""
# Wait for a stopped event message in the stopped queue
# This message is used for triggering the 'threads' request
Expand Down Expand Up @@ -454,7 +459,7 @@ def start(self):
self.debugpy_client.connect_tcp_socket()
return self.debugpy_initialized

def stop(self):
def stop(self) -> None:
"""Stop the debugger."""
self.debugpy_client.disconnect_tcp_socket()

Expand Down
Loading