Skip to content

Commit 72e89d1

Browse files
committed
Annotate the news items that are trigered by autotyping.
And move most `__init__` declaration to class level + default value when immutable.
1 parent 199f674 commit 72e89d1

8 files changed

Lines changed: 35 additions & 19 deletions

File tree

‎ipykernel/debugger.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ def __init__(self) -> None:
8181
class VariableExplorer:
8282
"""A variable explorer."""
8383

84+
frame: _FakeFrame | None = None
85+
8486
def __init__(self) -> None:
8587
"""Initialize the explorer."""
8688
self.suspended_frame_manager = SuspendedFramesManager()
8789
self.py_db = _DummyPyDB()
8890
self.tracker = _FramesTracker(self.suspended_frame_manager, self.py_db)
89-
self.frame = None
9091

9192
def track(self) -> None:
9293
"""Start tracking."""
@@ -307,6 +308,10 @@ async def send_dap_request(self, msg):
307308
class Debugger:
308309
"""The debugger class."""
309310

311+
breakpoint_list: dict[str, t.Any]
312+
stopped_threads: set[int]
313+
_removed_cleanup: dict[int, t.Any]
314+
310315
# Requests that requires that the debugger has started
311316
started_debug_msg_types = [
312317
"dumpCell",

‎ipykernel/displayhook.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ class ZMQDisplayHook:
2323

2424
topic = b"execute_result"
2525

26+
_parent_header: ContextVar[dict[str, Any]]
27+
_parent_header_global: dict[str, t.Any]
28+
2629
def __init__(self, session, pub_socket) -> None:
2730
"""Initialize the hook."""
2831
self.session = session
2932
self.pub_socket = pub_socket
3033

31-
self._parent_header: ContextVar[dict[str, Any]] = ContextVar("parent_header")
34+
self._parent_header = ContextVar("parent_header")
3235
self._parent_header.set({})
3336
self._parent_header_global = {}
3437

@@ -92,6 +95,7 @@ class ZMQShellDisplayHook(DisplayHook):
9295
session = Instance(Session, allow_none=True)
9396
pub_socket = Any(allow_none=True)
9497
_parent_header: ContextVar[dict[str, Any]]
98+
_parent_header_global: dict[str, t.Any]
9599
_thread_local = Any()
96100
msg: dict[str, t.Any] | None
97101

‎ipykernel/gui/gtk3embed.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# stdlib
1313
import sys
1414
import warnings
15+
from collections.abc import Callable
16+
from typing import Any
1517

1618
# Third-party
1719
import gi
@@ -32,12 +34,13 @@
3234
class GTKEmbed:
3335
"""A class to embed a kernel into the GTK main event loop."""
3436

37+
# These two will later store the real gtk functions when we hijack them
38+
gtk_main = None
39+
gtk_main_quit: Callable[..., Any] | None = None
40+
3541
def __init__(self, kernel) -> None:
3642
"""Initialize the embed."""
3743
self.kernel = kernel
38-
# These two will later store the real gtk functions when we hijack them
39-
self.gtk_main = None
40-
self.gtk_main_quit = None
4144

4245
def start(self) -> None:
4346
"""Starts the GTK main event loop and sets our kernel startup routine."""

‎ipykernel/gui/gtkembed.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# stdlib
1313
import sys
1414
import warnings
15+
from collections.abc import Callable
16+
from typing import Any
1517

1618
# Third-party
1719
import gobject
@@ -29,12 +31,13 @@
2931
class GTKEmbed:
3032
"""A class to embed a kernel into the GTK main event loop."""
3133

34+
# These two will later store the real gtk functions when we hijack them
35+
gtk_main = None
36+
gtk_main_quit: Callable[..., Any] | None = None
37+
3238
def __init__(self, kernel) -> None:
3339
"""Initialize the embed."""
3440
self.kernel = kernel
35-
# These two will later store the real gtk functions when we hijack them
36-
self.gtk_main = None
37-
self.gtk_main_quit = None
3841

3942
def start(self) -> None:
4043
"""Starts the GTK main event loop and sets our kernel startup routine."""

‎ipykernel/iostream.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ class OutStream(TextIOBase):
448448
topic = None
449449
encoding = "UTF-8"
450450
_exc: Any | None = None
451+
_parent_header: contextvars.ContextVar[dict[str, Any]]
452+
_parent_header_global: dict[str, Any]
453+
_buffers: defaultdict[frozenset[tuple[str, Any]], StringIO]
451454

452455
def fileno(self):
453456
"""
@@ -539,9 +542,7 @@ def __init__(
539542
self.pub_thread = pub_thread
540543
self.name = name
541544
self.topic = b"stream." + name.encode()
542-
self._parent_header: contextvars.ContextVar[dict[str, Any]] = contextvars.ContextVar(
543-
"parent_header"
544-
)
545+
self._parent_header = contextvars.ContextVar("parent_header")
545546
self._parent_header.set({})
546547
self._parent_header_global = {}
547548
self._master_pid = os.getpid()

‎ipykernel/trio_runner.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
class TrioRunner:
1414
"""A trio loop runner."""
1515

16-
def __init__(self) -> None:
17-
"""Initialize the runner."""
18-
self._cell_cancel_scope = None
19-
self._trio_token = None
16+
_cell_cancel_scope: trio.CancelScope | None = None
17+
_trio_token: trio.lowlevel.TrioToken | None = None
2018

2119
def initialize(self, kernel, io_loop) -> None:
2220
"""Initialize the runner."""

‎ipykernel/zmqshell.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ZMQDisplayPublisher(DisplayPublisher):
5858
session = Instance(Session, allow_none=True)
5959
pub_socket = Any(allow_none=True)
6060
_parent_header: contextvars.ContextVar[dict[str, Any]]
61+
_parent_header_global: dict[str, Any]
6162
topic = CBytes(b"display_data")
6263

6364
store_display_history = Bool(
@@ -526,6 +527,9 @@ def subshell(self, arg_s):
526527
class ZMQInteractiveShell(InteractiveShell):
527528
"""A subclass of InteractiveShell for ZMQ."""
528529

530+
_parent_header: contextvars.ContextVar[dict[str, typing.Any]]
531+
_parent_header_global: dict[str, typing.Any]
532+
529533
def __init__(self, *args, **kwargs) -> None:
530534
super().__init__(*args, **kwargs)
531535

@@ -546,9 +550,7 @@ def __init__(self, *args, **kwargs) -> None:
546550
if "IPKernelApp" not in self.config:
547551
self.config.IPKernelApp.tqdm = "dummy value for https://github.com/tqdm/tqdm/pull/1628"
548552

549-
self._parent_header: contextvars.ContextVar[dict[str, typing.Any]] = contextvars.ContextVar(
550-
"parent_header"
551-
)
553+
self._parent_header = contextvars.ContextVar("parent_header")
552554
self._parent_header.set({})
553555
self._parent_header_global = {}
554556

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ build = [
128128
[tool.mypy]
129129
files = "ipykernel"
130130
strict = true
131-
disable_error_code = ["no-untyped-def", "no-untyped-call", "import-not-found"]
131+
disable_error_code = ["no-untyped-def", "no-untyped-call", "import-not-found", "untyped-decorator"]
132132
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
133133
follow_imports = "normal"
134134
pretty = true

0 commit comments

Comments
 (0)