Skip to content

Commit 1786e15

Browse files
authored
don't require IJupyterConnection to be IDiposable (#2887)
* address the feedback around requiring IJupyterConnection to always be disposable. * fix test since API changed
1 parent be351f6 commit 1786e15

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.jupyter_api_is_not_changed.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Microsoft.DotNet.Interactive.Jupyter
118118
public static System.String input(System.String prompt = )
119119
public static Microsoft.DotNet.Interactive.PasswordString password(System.String prompt = )
120120
Microsoft.DotNet.Interactive.Jupyter.Connection
121-
public abstract class IJupyterConnection, System.IDisposable
121+
public abstract class IJupyterConnection
122122
public System.Threading.Tasks.Task<IJupyterKernelConnection> CreateKernelConnectionAsync(System.String kernelSpecName)
123123
public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.Jupyter.KernelSpec>> GetKernelSpecsAsync()
124124
public abstract class IJupyterKernelConnection, System.IDisposable

src/Microsoft.DotNet.Interactive.Jupyter.Tests/TestJupyterConnectionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public async Task StartAsync()
219219
public bool IsDisposed => _disposed;
220220
}
221221

222-
public class TestJupyterConnection : IJupyterConnection
222+
public class TestJupyterConnection : IJupyterConnection, IDisposable
223223
{
224224
private IJupyterConnection _testJupyterConnection;
225225
private TestJupyterKernelConnection _testKernelConnection;
@@ -254,7 +254,7 @@ public async Task<IJupyterKernelConnection> CreateKernelConnectionAsync(string k
254254

255255
public void Dispose()
256256
{
257-
_testJupyterConnection?.Dispose();
257+
(_testJupyterConnection as IDisposable)?.Dispose();
258258
_disposed = true;
259259
}
260260

src/Microsoft.DotNet.Interactive.Jupyter/ConnectJupyterKernelCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public override async Task<Kernel> ConnectKernelAsync(
6969
var localName = commandLineContext.ParseResult.GetValueForOption(KernelNameOption);
7070

7171
var kernel = await connector?.CreateKernelAsync(localName);
72-
kernel?.RegisterForDisposal(connection);
72+
if (connection is IDisposable disposableConnection)
73+
{
74+
kernel?.RegisterForDisposal(disposableConnection);
75+
}
7376
return kernel;
7477
}
7578

@@ -95,8 +98,8 @@ private IEnumerable<CompletionItem> GetKernelSpecsCompletions(CompletionContext
9598
}
9699

97100
IEnumerable<CompletionItem> completions;
98-
using (var connection = GetJupyterConnection(ctx.ParseResult))
99-
{
101+
var connection = GetJupyterConnection(ctx.ParseResult);
102+
using (connection as IDisposable) {
100103
completions = GetKernelSpecsCompletions(connection);
101104
}
102105

src/Microsoft.DotNet.Interactive.Jupyter/Connection/IJupyterConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.DotNet.Interactive.Jupyter.Connection;
99

10-
public interface IJupyterConnection : IDisposable
10+
public interface IJupyterConnection
1111
{
1212
Task<IEnumerable<KernelSpec>> GetKernelSpecsAsync();
1313

src/Microsoft.DotNet.Interactive.Jupyter/Http/JupyterHttpConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.DotNet.Interactive.Jupyter.Http;
1515

16-
internal class JupyterHttpConnection : IJupyterConnection
16+
internal class JupyterHttpConnection : IJupyterConnection, IDisposable
1717
{
1818
#region JsonTypes
1919
private class KernelSessionInfo

src/Microsoft.DotNet.Interactive.Jupyter/ZMQ/JupyterConnection.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ private Process CreateKernelProcess(KernelSpec spec, string connectionFilePath)
132132
return kernelProcess;
133133
}
134134

135-
public void Dispose()
136-
{
137-
}
138-
139135
private async Task<KernelSpec> GetKernelSpecAsync(string kernelSpecName)
140136
{
141137
var installedSpecs = await _getKernelSpecs;

0 commit comments

Comments
 (0)