|
| 1 | +Backported to 6.29.5 from https://github.com/ipython/ipykernel/pull/1277 |
| 2 | +See https://github.com/ipython/ipykernel/issues/1302 |
| 3 | + |
| 4 | +diff --git a/docs/conf.py b/docs/conf.py |
| 5 | +index 4bb59932..38a724b5 100644 |
| 6 | +--- a/docs/conf.py |
| 7 | ++++ b/docs/conf.py |
| 8 | +@@ -13,7 +13,7 @@ |
| 9 | + import os |
| 10 | + import shutil |
| 11 | + from pathlib import Path |
| 12 | +-from typing import Any, Dict, List |
| 13 | ++from typing import Any |
| 14 | + |
| 15 | + # If extensions (or modules to document with autodoc) are in another directory, |
| 16 | + # add these directories to sys.path here. If the directory is relative to the |
| 17 | +@@ -70,7 +70,7 @@ |
| 18 | + # built documents. |
| 19 | + # |
| 20 | + |
| 21 | +-version_ns: Dict[str, Any] = {} |
| 22 | ++version_ns: dict[str, Any] = {} |
| 23 | + here = Path(__file__).parent.resolve() |
| 24 | + version_py = Path(here) / os.pardir / "ipykernel" / "_version.py" |
| 25 | + with open(version_py) as f: |
| 26 | +@@ -159,7 +159,7 @@ |
| 27 | + # Add any paths that contain custom static files (such as style sheets) here, |
| 28 | + # relative to this directory. They are copied after the builtin static files, |
| 29 | + # so a file named "default.css" will overwrite the builtin "default.css". |
| 30 | +-html_static_path: List[str] = [] |
| 31 | ++html_static_path: list[str] = [] |
| 32 | + |
| 33 | + # Add any extra paths that contain custom files (such as robots.txt or |
| 34 | + # .htaccess) here, relative to this directory. These files are copied |
| 35 | +@@ -226,7 +226,7 @@ |
| 36 | + |
| 37 | + # -- Options for LaTeX output --------------------------------------------- |
| 38 | + |
| 39 | +-latex_elements: Dict[str, object] = {} |
| 40 | ++latex_elements: dict[str, object] = {} |
| 41 | + |
| 42 | + # Grouping the document tree into LaTeX files. List of tuples |
| 43 | + # (source start file, target name, title, |
| 44 | +diff --git a/ipykernel/_version.py b/ipykernel/_version.py |
| 45 | +index d9a9f534..5907d150 100644 |
| 46 | +--- a/ipykernel/_version.py |
| 47 | ++++ b/ipykernel/_version.py |
| 48 | +@@ -2,7 +2,6 @@ |
| 49 | + store the current version info of the server. |
| 50 | + """ |
| 51 | + import re |
| 52 | +-from typing import List |
| 53 | + |
| 54 | + # Version string must appear intact for hatch versioning |
| 55 | + __version__ = "7.0.0a0" |
| 56 | +@@ -11,7 +10,7 @@ |
| 57 | + pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)" |
| 58 | + match = re.match(pattern, __version__) |
| 59 | + assert match is not None |
| 60 | +-parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]] |
| 61 | ++parts: list[object] = [int(match[part]) for part in ["major", "minor", "patch"]] |
| 62 | + if match["rest"]: |
| 63 | + parts.append(match["rest"]) |
| 64 | + version_info = tuple(parts) |
| 65 | +diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py |
| 66 | +index 8680793f..780d1801 100644 |
| 67 | +--- a/ipykernel/debugger.py |
| 68 | ++++ b/ipykernel/debugger.py |
| 69 | +@@ -130,7 +130,7 @@ def _reset_tcp_pos(self): |
| 70 | + |
| 71 | + def _put_message(self, raw_msg): |
| 72 | + self.log.debug("QUEUE - _put_message:") |
| 73 | +- msg = t.cast(t.Dict[str, t.Any], jsonapi.loads(raw_msg)) |
| 74 | ++ msg = t.cast(dict[str, t.Any], jsonapi.loads(raw_msg)) |
| 75 | + if msg["type"] == "event": |
| 76 | + self.log.debug("QUEUE - received event:") |
| 77 | + self.log.debug(msg) |
| 78 | +diff --git a/ipykernel/inprocess/channels.py b/ipykernel/inprocess/channels.py |
| 79 | +index 378416dc..4c01c5bc 100644 |
| 80 | +--- a/ipykernel/inprocess/channels.py |
| 81 | ++++ b/ipykernel/inprocess/channels.py |
| 82 | +@@ -3,8 +3,6 @@ |
| 83 | + # Copyright (c) IPython Development Team. |
| 84 | + # Distributed under the terms of the Modified BSD License. |
| 85 | + |
| 86 | +-from typing import List |
| 87 | +- |
| 88 | + from jupyter_client.channelsabc import HBChannelABC |
| 89 | + |
| 90 | + # ----------------------------------------------------------------------------- |
| 91 | +@@ -15,7 +13,7 @@ |
| 92 | + class InProcessChannel: |
| 93 | + """Base class for in-process channels.""" |
| 94 | + |
| 95 | +- proxy_methods: List[object] = [] |
| 96 | ++ proxy_methods: list[object] = [] |
| 97 | + |
| 98 | + def __init__(self, client=None): |
| 99 | + """Initialize the channel.""" |
| 100 | +diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py |
| 101 | +index beca44b1..81170b97 100644 |
| 102 | +--- a/ipykernel/iostream.py |
| 103 | ++++ b/ipykernel/iostream.py |
| 104 | +@@ -15,7 +15,7 @@ |
| 105 | + from collections import defaultdict, deque |
| 106 | + from io import StringIO, TextIOBase |
| 107 | + from threading import local |
| 108 | +-from typing import Any, Callable, Deque, Dict, Optional |
| 109 | ++from typing import Any, Callable, Optional |
| 110 | + |
| 111 | + import zmq |
| 112 | + from jupyter_client.session import extract_header |
| 113 | +@@ -94,8 +94,8 @@ def __init__(self, socket, pipe=False): |
| 114 | + if pipe: |
| 115 | + self._setup_pipe_in() |
| 116 | + self._local = threading.local() |
| 117 | +- self._events: Deque[Callable[..., Any]] = deque() |
| 118 | +- self._event_pipes: Dict[threading.Thread, Any] = {} |
| 119 | ++ self._events: deque[Callable[..., Any]] = deque() |
| 120 | ++ self._event_pipes: dict[threading.Thread, Any] = {} |
| 121 | + self._event_pipe_gc_lock: threading.Lock = threading.Lock() |
| 122 | + self._event_pipe_gc_seconds: float = 10 |
| 123 | + self._setup_event_pipe() |
| 124 | +@@ -470,7 +470,7 @@ def __init__( |
| 125 | + self.pub_thread = pub_thread |
| 126 | + self.name = name |
| 127 | + self.topic = b"stream." + name.encode() |
| 128 | +- self._parent_header: contextvars.ContextVar[Dict[str, Any]] = contextvars.ContextVar( |
| 129 | ++ self._parent_header: contextvars.ContextVar[dict[str, Any]] = contextvars.ContextVar( |
| 130 | + "parent_header" |
| 131 | + ) |
| 132 | + self._parent_header.set({}) |
| 133 | +diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py |
| 134 | +index db83d986..48efa6cd 100644 |
| 135 | +--- a/ipykernel/ipkernel.py |
| 136 | ++++ b/ipykernel/ipkernel.py |
| 137 | +@@ -1,5 +1,7 @@ |
| 138 | + """The IPython kernel implementation""" |
| 139 | + |
| 140 | ++from __future__ import annotations |
| 141 | ++ |
| 142 | + import asyncio |
| 143 | + import builtins |
| 144 | + import gc |
| 145 | +@@ -16,7 +18,7 @@ |
| 146 | + from IPython.core import release |
| 147 | + from IPython.utils.tokenutil import line_at_cursor, token_at_cursor |
| 148 | + from jupyter_client.session import extract_header |
| 149 | +-from traitlets import Any, Bool, HasTraits, Instance, List, Type, observe, observe_compat |
| 150 | ++from traitlets import Any, Bool, HasTraits, Instance, List, Type, default, observe, observe_compat |
| 151 | + from zmq.eventloop.zmqstream import ZMQStream |
| 152 | + |
| 153 | + from .comm.comm import BaseComm |
| 154 | +@@ -46,7 +48,7 @@ def _create_comm(*args, **kwargs): |
| 155 | + |
| 156 | + # there can only be one comm manager in a ipykernel process |
| 157 | + _comm_lock = threading.Lock() |
| 158 | +-_comm_manager: t.Optional[CommManager] = None |
| 159 | ++_comm_manager: CommManager | None = None |
| 160 | + |
| 161 | + |
| 162 | + def _get_comm_manager(*args, **kwargs): |
| 163 | +@@ -84,7 +86,11 @@ def _user_module_changed(self, change): |
| 164 | + if self.shell is not None: |
| 165 | + self.shell.user_module = change["new"] |
| 166 | + |
| 167 | +- user_ns = Instance(dict, args=None, allow_none=True) |
| 168 | ++ user_ns = Instance("collections.abc.Mapping", allow_none=True) |
| 169 | ++ |
| 170 | ++ @default("user_ns") |
| 171 | ++ def _default_user_ns(self): |
| 172 | ++ return dict() |
| 173 | + |
| 174 | + @observe("user_ns") |
| 175 | + @observe_compat |
| 176 | +@@ -353,7 +359,7 @@ async def do_execute( |
| 177 | + |
| 178 | + self._forward_input(allow_stdin) |
| 179 | + |
| 180 | +- reply_content: t.Dict[str, t.Any] = {} |
| 181 | ++ reply_content: dict[str, t.Any] = {} |
| 182 | + if hasattr(shell, "run_cell_async") and hasattr(shell, "should_run_async"): |
| 183 | + run_cell = shell.run_cell_async |
| 184 | + should_run_async = shell.should_run_async |
| 185 | +@@ -559,7 +565,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()): |
| 186 | + """Handle code inspection.""" |
| 187 | + name = token_at_cursor(code, cursor_pos) |
| 188 | + |
| 189 | +- reply_content: t.Dict[str, t.Any] = {"status": "ok"} |
| 190 | ++ reply_content: dict[str, t.Any] = {"status": "ok"} |
| 191 | + reply_content["data"] = {} |
| 192 | + reply_content["metadata"] = {} |
| 193 | + assert self.shell is not None |
| 194 | +@@ -755,7 +761,7 @@ def init_closure(self: threading.Thread, *args, **kwargs): |
| 195 | + threading.Thread.run = run_closure # type:ignore[method-assign] |
| 196 | + |
| 197 | + def _clean_thread_parent_frames( |
| 198 | +- self, phase: t.Literal["start", "stop"], info: t.Dict[str, t.Any] |
| 199 | ++ self, phase: t.Literal["start", "stop"], info: dict[str, t.Any] |
| 200 | + ): |
| 201 | + """Clean parent frames of threads which are no longer running. |
| 202 | + This is meant to be invoked by garbage collector callback hook. |
| 203 | +diff --git a/ipykernel/pickleutil.py b/ipykernel/pickleutil.py |
| 204 | +index 6f156594..4ffa5262 100644 |
| 205 | +--- a/ipykernel/pickleutil.py |
| 206 | ++++ b/ipykernel/pickleutil.py |
| 207 | +@@ -209,7 +209,7 @@ def __init__(self, f): |
| 208 | + """Initialize the can""" |
| 209 | + self._check_type(f) |
| 210 | + self.code = f.__code__ |
| 211 | +- self.defaults: typing.Optional[typing.List[typing.Any]] |
| 212 | ++ self.defaults: typing.Optional[list[typing.Any]] |
| 213 | + if f.__defaults__: |
| 214 | + self.defaults = [can(fd) for fd in f.__defaults__] |
| 215 | + else: |
| 216 | +@@ -475,7 +475,7 @@ def uncan_sequence(obj, g=None): |
| 217 | + if buffer is not memoryview: |
| 218 | + can_map[buffer] = CannedBuffer |
| 219 | + |
| 220 | +-uncan_map: typing.Dict[type, typing.Any] = { |
| 221 | ++uncan_map: dict[type, typing.Any] = { |
| 222 | + CannedObject: lambda obj, g: obj.get_object(g), |
| 223 | + dict: uncan_dict, |
| 224 | + } |
| 225 | +diff --git a/pyproject.toml b/pyproject.toml |
| 226 | +index 1e9e543c..e1d7b1d5 100644 |
| 227 | +--- a/pyproject.toml |
| 228 | ++++ b/pyproject.toml |
| 229 | +@@ -187,6 +187,9 @@ filterwarnings= [ |
| 230 | + |
| 231 | + # Ignore datetime warning. |
| 232 | + "ignore:datetime.datetime.utc:DeprecationWarning", |
| 233 | ++ |
| 234 | ++ # ignore unclosed sqlite in traits |
| 235 | ++ "ignore:unclosed database in <sqlite3.Connection:ResourceWarning", |
| 236 | + ] |
| 237 | + |
| 238 | + [tool.coverage.report] |
0 commit comments