Skip to content

Commit 6be7179

Browse files
committed
accept Mapping in Kernel.user_ns instead of dict
accepts FrameLocalsProxy (new in Python 3.13) for embed_kernel
1 parent 9166b65 commit 6be7179

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ipykernel/ipkernel.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""The IPython kernel implementation"""
22

3+
from __future__ import annotations
4+
35
import builtins
46
import gc
57
import getpass
68
import os
79
import sys
810
import threading
911
import typing as t
12+
from collections.abc import Mapping
1013
from dataclasses import dataclass
1114

1215
import comm
@@ -46,7 +49,7 @@ def _create_comm(*args, **kwargs):
4649

4750
# there can only be one comm manager in a ipykernel process
4851
_comm_lock = threading.Lock()
49-
_comm_manager: t.Optional[CommManager] = None
52+
_comm_manager: CommManager | None = None
5053

5154

5255
def _get_comm_manager(*args, **kwargs):
@@ -84,7 +87,7 @@ def _user_module_changed(self, change):
8487
if self.shell is not None:
8588
self.shell.user_module = change["new"]
8689

87-
user_ns = Instance(dict, args=None, allow_none=True)
90+
user_ns = Instance(Mapping, args=None, allow_none=True)
8891

8992
@observe("user_ns")
9093
@observe_compat
@@ -353,7 +356,7 @@ async def do_execute(
353356

354357
self._forward_input(allow_stdin)
355358

356-
reply_content: t.Dict[str, t.Any] = {}
359+
reply_content: dict[str, t.Any] = {}
357360
if hasattr(shell, "run_cell_async") and hasattr(shell, "should_run_async"):
358361
run_cell = shell.run_cell_async
359362
should_run_async = shell.should_run_async
@@ -559,7 +562,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
559562
"""Handle code inspection."""
560563
name = token_at_cursor(code, cursor_pos)
561564

562-
reply_content: t.Dict[str, t.Any] = {"status": "ok"}
565+
reply_content: dict[str, t.Any] = {"status": "ok"}
563566
reply_content["data"] = {}
564567
reply_content["metadata"] = {}
565568
assert self.shell is not None
@@ -755,7 +758,7 @@ def init_closure(self: threading.Thread, *args, **kwargs):
755758
threading.Thread.run = run_closure # type:ignore[method-assign]
756759

757760
def _clean_thread_parent_frames(
758-
self, phase: t.Literal["start", "stop"], info: t.Dict[str, t.Any]
761+
self, phase: t.Literal["start", "stop"], info: dict[str, t.Any]
759762
):
760763
"""Clean parent frames of threads which are no longer running.
761764
This is meant to be invoked by garbage collector callback hook.

0 commit comments

Comments
 (0)