From d445c2dba32397f4568ee34ffaeb45346e19f021 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 2 Nov 2016 15:49:39 -0700 Subject: [PATCH 1/2] Add a test failing if getpass does not acceptthe stream parameter --- ipykernel/inprocess/tests/test_kernel.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ipykernel/inprocess/tests/test_kernel.py b/ipykernel/inprocess/tests/test_kernel.py index 8f15376f7..0231c8688 100644 --- a/ipykernel/inprocess/tests/test_kernel.py +++ b/ipykernel/inprocess/tests/test_kernel.py @@ -66,3 +66,11 @@ def test_stdout(self): kc.execute('print("bar")') out, err = assemble_output(kc.iopub_channel) self.assertEqual(out, 'bar\n') + + def test_getpass_stream(self): + "Tests that kernel getpass accept the stream parameter" + kernel = InProcessKernel() + kernel._allow_stdin = True + kernel._input_request = lambda *args, **kwargs : None + + kernel.getpass(stream='non empty') From 4be0a55aef59e8d6eed0e9c68b07b20edb51c26c Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 2 Nov 2016 15:44:13 -0700 Subject: [PATCH 2/2] Allow ipykernel getpass to take a stream argument. The original getpass.getpass takes it so this restore API compatibility. --- ipykernel/kernelbase.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index eb24b7448..64e6737e4 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -656,7 +656,7 @@ def _no_raw_input(self): raise StdinNotImplementedError("raw_input was called, but this " "frontend does not support stdin.") - def getpass(self, prompt=''): + def getpass(self, prompt='', stream=None): """Forward getpass to frontends Raises @@ -667,6 +667,10 @@ def getpass(self, prompt=''): raise StdinNotImplementedError( "getpass was called, but this frontend does not support input requests." ) + if stream is not None: + import warnings + warnings.warn("The `stream` parameter of `getpass.getpass` will have no effect when using ipykernel", + UserWarning, stacklevel=2) return self._input_request(prompt, self._parent_ident, self._parent_header,