Skip to content

Commit bfdd1d1

Browse files
committed
fix typing
1 parent 592d18d commit bfdd1d1

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

jupyter_server/gateway/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async def get_kernel_spec_resource(self, kernel_name, path):
318318
class GatewaySessionManager(SessionManager):
319319
kernel_manager = Instance("jupyter_server.gateway.managers.GatewayMappingKernelManager")
320320

321-
async def kernel_culled(self, kernel_id: str) -> bool:
321+
async def kernel_culled(self, kernel_id: str) -> bool: # typing: ignore
322322
"""Checks if the kernel is still considered alive and returns true if it's not found."""
323323
km: Optional[GatewayKernelManager] = None
324324
try:

jupyter_server/services/kernels/kernelmanager.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Distributed under the terms of the Modified BSD License.
88
import asyncio
99
import os
10+
import typing as t
1011
import warnings
1112
from collections import defaultdict
1213
from datetime import datetime, timedelta
@@ -58,7 +59,7 @@ def _default_kernel_manager_class(self):
5859

5960
_kernel_connections = Dict()
6061

61-
_kernel_ports: DictType[str, str] = Dict() # type: ignore
62+
_kernel_ports: DictType[str, t.List[int]] = Dict() # type: ignore
6263

6364
_culler_callback = None
6465

@@ -196,24 +197,30 @@ async def _remove_kernel_when_ready(self, kernel_id, kernel_awaitable):
196197
self._kernel_connections.pop(kernel_id, None)
197198
self._kernel_ports.pop(kernel_id, None)
198199

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.
199205
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
201207
) -> str:
202208
"""Start a kernel for a session and return its kernel_id.
203209
204210
Parameters
205211
----------
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.
206215
kernel_id : uuid (str)
207216
The uuid to associate the new kernel with. If this
208217
is not None, this kernel will be persistent whenever it is
209218
requested.
210219
path : API path
211220
The API path (unicode, '/' delimited) for the cwd.
212221
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.
216222
"""
223+
kernel_id = kwargs.pop("kernel_id")
217224
if kernel_id is None or kernel_id not in self:
218225
if path is not None:
219226
kwargs["cwd"] = self.cwd_for_path(path, env=kwargs.get("env", {}))
@@ -301,6 +308,8 @@ def _get_changed_ports(self, kernel_id):
301308
"""
302309
# Get current ports and return comparison with ports captured at startup.
303310
km = self.get_kernel(kernel_id)
311+
assert isinstance(km.ports, list)
312+
assert isinstance(self._kernel_ports[kernel_id], list)
304313
if km.ports != self._kernel_ports[kernel_id]:
305314
return km.ports
306315
return None

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ async def update_session(self, session_id, **kwargs):
449449
query = "UPDATE session SET %s WHERE session_id=?" % (", ".join(sets))
450450
self.cursor.execute(query, list(kwargs.values()) + [session_id])
451451

452-
def kernel_culled(self, kernel_id: str) -> bool:
452+
async def kernel_culled(self, kernel_id: str) -> bool:
453453
"""Checks if the kernel is still considered alive and returns true if its not found."""
454454
return kernel_id not in self.kernel_manager
455455

0 commit comments

Comments
 (0)