Skip to content

Commit acff147

Browse files
authored
Data Explorer: Update Python kernel to latest comm definition, fix Optional logic error (#5514)
Gardening related to #5128. Optional frontend method parameters were not handled in TypeScript or Python (but they were in Rust), so this has been fixed to be consistent.
1 parent d93c18f commit acff147

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer_comm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,10 @@ class ReturnColumnProfilesParams(BaseModel):
15941594
description="Array of individual column profile results",
15951595
)
15961596

1597+
error_message: Optional[StrictStr] = Field(
1598+
description="Optional error message if something failed to compute",
1599+
)
1600+
15971601

15981602
OpenDatasetResult.update_forward_refs()
15991603

positron/comms/data_explorer-frontend-openrpc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
{
4545
"name": "error_message",
4646
"description": "Optional error message if something failed to compute",
47+
"required": false,
4748
"schema": {
4849
"type": "string"
4950
}

positron/comms/generate-comms.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,17 @@ from ._vendor.pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictI
10581058
yield ` """\n`;
10591059
yield `\n`;
10601060
for (const param of method.params) {
1061+
yield ` ${param.name}: `;
1062+
if (isOptional(param)) {
1063+
yield `Optional[`;
1064+
}
10611065
if (param.schema.enum) {
1062-
yield ` ${param.name}: ${snakeCaseToSentenceCase(method.name)}${snakeCaseToSentenceCase(param.name)}`;
1066+
yield `${snakeCaseToSentenceCase(method.name)}${snakeCaseToSentenceCase(param.name)}`;
10631067
} else {
1064-
yield ` ${param.name}: ${deriveType(contracts, PythonTypeMap, [param.name], param.schema)}`;
1068+
yield `${deriveType(contracts, PythonTypeMap, [param.name], param.schema)}`;
1069+
}
1070+
if (isOptional(param)) {
1071+
yield `]`;
10651072
}
10661073
yield ' = Field(\n';
10671074
yield ` description="${param.description}",\n`;
@@ -1315,7 +1322,11 @@ import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/co
13151322
yield '\t/**\n';
13161323
yield formatComment('\t * ', `${param.description}`);
13171324
yield '\t */\n';
1318-
yield `\t${param.name}: `;
1325+
yield `\t${param.name}`;
1326+
if (isOptional(param)) {
1327+
yield '?';
1328+
}
1329+
yield ': ';
13191330
if (param.schema.type === 'string' && param.schema.enum) {
13201331
yield `${snakeCaseToSentenceCase(method.name)}${snakeCaseToSentenceCase(param.name)}`;
13211332
} else {

0 commit comments

Comments
 (0)