From caa3fe7f3d6e664b5155d2f255dd9dcaf785a242 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Fri, 23 Dec 2022 13:32:59 +0100 Subject: [PATCH] MAINT: [_async_]start_kernel should only take kwarg only. The base cases only take **kw, so you can't have subclass also take positional arguments. It is problematic to allow positional arguments, as is someone code against a subclass it is not swappable for another one. The latest version of jupyter_server also seem to sometime have subclasses that have the signature with kernel_name first and other with kernel_id first, with is a recipe for disaster if we don't make it kwarg only. This is I belove not caught by mypy because of multiple reason: 1) the use of run_sync in a couple of place, 2) method assignement might not be handled by mypy. --- jupyter_client/multikernelmanager.py | 2 +- tests/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_client/multikernelmanager.py b/jupyter_client/multikernelmanager.py index e707c8cc4..e02bb1a3f 100644 --- a/jupyter_client/multikernelmanager.py +++ b/jupyter_client/multikernelmanager.py @@ -184,7 +184,7 @@ def _using_pending_kernels(self): return getattr(self, 'use_pending_kernels', False) async def _async_start_kernel( - self, kernel_name: t.Optional[str] = None, **kwargs: t.Any + self, *, kernel_name: t.Optional[str] = None, **kwargs: t.Any ) -> str: """Start a new kernel. diff --git a/tests/utils.py b/tests/utils.py index 0c617d3a7..d4cc9c843 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -171,11 +171,11 @@ def remove_kernel(self, kernel_id): """Record call and defer to superclass""" @subclass_recorder - def start_kernel(self, kernel_name=None, **kwargs): + def start_kernel(self, *, kernel_name=None, **kwargs): """Record call and defer to superclass""" @subclass_recorder - def _async_start_kernel(self, kernel_name=None, **kwargs): + def _async_start_kernel(self, *, kernel_name=None, **kwargs): """Record call and defer to superclass""" @subclass_recorder