Skip to content

Commit 7656b8a

Browse files
committed
force user_ns to be a dict, as we call .clear() on it in IPython
1 parent 6dd8fed commit 7656b8a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ipykernel/embed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def embed_kernel(module=None, local_ns=None, **kwargs):
5252
local_ns = caller_locals
5353

5454
app.kernel.user_module = module
55+
assert isinstance(local_ns, dict)
5556
app.kernel.user_ns = local_ns
5657
app.shell.set_completer_frame() # type:ignore[union-attr]
5758
app.start()

ipykernel/ipkernel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@
1818
from IPython.core import release
1919
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
2020
from jupyter_client.session import extract_header
21-
from traitlets import Any, Bool, HasTraits, Instance, List, Type, default, observe, observe_compat
21+
from traitlets import (
22+
Any,
23+
Bool,
24+
Dict,
25+
HasTraits,
26+
Instance,
27+
List,
28+
Type,
29+
default,
30+
observe,
31+
observe_compat,
32+
)
2233

2334
from .comm.comm import BaseComm
2435
from .comm.manager import CommManager
@@ -86,7 +97,7 @@ def _user_module_changed(self, change):
8697
if self.shell is not None:
8798
self.shell.user_module = change["new"]
8899

89-
user_ns = Instance("collections.abc.Mapping", allow_none=True)
100+
user_ns = Dict(allow_none=True)
90101

91102
@default("user_ns")
92103
def _default_user_ns(self):

0 commit comments

Comments
 (0)