|
7 | 7 | # Distributed under the terms of the Modified BSD License.
|
8 | 8 | import asyncio
|
9 | 9 | import os
|
| 10 | +import typing as t |
10 | 11 | import warnings
|
11 | 12 | from collections import defaultdict
|
12 | 13 | from datetime import datetime, timedelta
|
@@ -58,7 +59,7 @@ def _default_kernel_manager_class(self):
|
58 | 59 |
|
59 | 60 | _kernel_connections = Dict()
|
60 | 61 |
|
61 |
| - _kernel_ports: DictType[str, str] = Dict() # type: ignore |
| 62 | + _kernel_ports: DictType[str, t.List[int]] = Dict() # type: ignore |
62 | 63 |
|
63 | 64 | _culler_callback = None
|
64 | 65 |
|
@@ -196,24 +197,30 @@ async def _remove_kernel_when_ready(self, kernel_id, kernel_awaitable):
|
196 | 197 | self._kernel_connections.pop(kernel_id, None)
|
197 | 198 | self._kernel_ports.pop(kernel_id, None)
|
198 | 199 |
|
| 200 | + # note: Kernel_name is not used, but we have to take it as a fist |
| 201 | + # parameter as this is the first argument taken by the superclass, and the |
| 202 | + # Liskov Substitution Principle (LSP) states that objects of a superclass |
| 203 | + # should be replaceable with objects of its subclasses without breaking |
| 204 | + # the application. |
199 | 205 | async def _async_start_kernel(
|
200 |
| - self, kernel_id: Optional[str] = None, path: Optional[ApiPath] = None, **kwargs: str |
| 206 | + self, kernel_name: Optional[str] = None, path: Optional[ApiPath] = None, **kwargs: str |
201 | 207 | ) -> str:
|
202 | 208 | """Start a kernel for a session and return its kernel_id.
|
203 | 209 |
|
204 | 210 | Parameters
|
205 | 211 | ----------
|
| 212 | + kernel_name : str |
| 213 | + The name identifying which kernel spec to launch. This is ignored if |
| 214 | + an existing kernel is returned, but it may be checked in the future. |
206 | 215 | kernel_id : uuid (str)
|
207 | 216 | The uuid to associate the new kernel with. If this
|
208 | 217 | is not None, this kernel will be persistent whenever it is
|
209 | 218 | requested.
|
210 | 219 | path : API path
|
211 | 220 | The API path (unicode, '/' delimited) for the cwd.
|
212 | 221 | Will be transformed to an OS path relative to root_dir.
|
213 |
| - kernel_name : str |
214 |
| - The name identifying which kernel spec to launch. This is ignored if |
215 |
| - an existing kernel is returned, but it may be checked in the future. |
216 | 222 | """
|
| 223 | + kernel_id = kwargs.pop("kernel_id") |
217 | 224 | if kernel_id is None or kernel_id not in self:
|
218 | 225 | if path is not None:
|
219 | 226 | kwargs["cwd"] = self.cwd_for_path(path, env=kwargs.get("env", {}))
|
@@ -301,6 +308,8 @@ def _get_changed_ports(self, kernel_id):
|
301 | 308 | """
|
302 | 309 | # Get current ports and return comparison with ports captured at startup.
|
303 | 310 | km = self.get_kernel(kernel_id)
|
| 311 | + assert isinstance(km.ports, list) |
| 312 | + assert isinstance(self._kernel_ports[kernel_id], list) |
304 | 313 | if km.ports != self._kernel_ports[kernel_id]:
|
305 | 314 | return km.ports
|
306 | 315 | return None
|
|
0 commit comments