Skip to content

Commit dba3cab

Browse files
authored
fix: typing of pdl_context in notebook extension and ast (#974)
Signed-off-by: Louis Mandel <[email protected]>
1 parent 6200a71 commit dba3cab

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,16 +2406,6 @@ export type PdlModelInput =
24062406
*
24072407
*/
24082408
export type Platform = "granite-io"
2409-
/**
2410-
* Backend name and configuration.
2411-
*
2412-
*/
2413-
export type Backend =
2414-
| LocalizedExpression
2415-
| string
2416-
| {
2417-
[k: string]: unknown
2418-
}
24192409
/**
24202410
* Parameters sent to the model.
24212411
*
@@ -3220,7 +3210,7 @@ export interface GraniteioModelBlock {
32203210
pdl__usage?: PdlUsage | null
32213211
pdl__model_input?: PdlModelInput
32223212
platform?: Platform
3223-
backend: Backend
3213+
backend: unknown
32243214
processor?: unknown
32253215
parameters?: Parameters
32263216
}

pdl-live-react/src/pdl_ast_utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { match, P } from "ts-pattern"
22

3-
import { Backend, PdlBlock } from "./pdl_ast"
3+
import { PdlBlock } from "./pdl_ast"
44
import { ExpressionT, isArgs } from "./helpers"
55

66
export function map_block_children(
@@ -72,8 +72,7 @@ export function map_block_children(
7272
const parameters: Parameters = block.parameters
7373
? f_expr(block.parameters)
7474
: undefined
75-
// @ts-expect-error: f_expr does not preserve the type of the expression
76-
const backend: Backend = f_expr(block.backend)
75+
const backend = f_expr(block.backend)
7776
const processor = block.processor ? f_expr(block.processor) : undefined
7877
return {
7978
...block,

src/pdl/pdl-schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4612,7 +4612,8 @@
46124612
{
46134613
"additionalProperties": true,
46144614
"type": "object"
4615-
}
4615+
},
4616+
{}
46164617
],
46174618
"description": "Backend name and configuration.\n ",
46184619
"title": "Backend"

src/pdl/pdl_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class GraniteioModelBlock(ModelBlock):
551551
model: ExpressionType[str]
552552
"""Model name used by the backend.
553553
"""
554-
backend: ExpressionType[str | dict[str, Any | object]]
554+
backend: ExpressionType[str | dict[str, Any] | object]
555555
"""Backend name and configuration.
556556
"""
557557
processor: Optional[ExpressionType[str | object]] = None

src/pdl/pdl_notebook_ext.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
from .pdl import InterpreterConfig, exec_str
99
from .pdl_ast import get_default_model_parameters
10+
from .pdl_context import DependentContext
1011
from .pdl_dumper import block_to_dict
11-
from .pdl_lazy import PdlDict, PdlList
12+
from .pdl_lazy import PdlDict
1213

1314

1415
@magics_class
@@ -33,10 +34,12 @@ def pdl(self, line, cell, local_ns):
3334
line = line.strip()
3435
args = parse_argstring(self.pdl, line)
3536
if args.reset_context:
36-
scope = local_ns | {"pdl_context": PdlList([])}
37+
scope = local_ns | {"pdl_context": DependentContext([])}
3738
else:
3839
# local_ns won't be lazy; make it lazy again
39-
scope = local_ns | {"pdl_context": PdlList(local_ns.get("pdl_context", []))}
40+
scope = local_ns | {
41+
"pdl_context": local_ns.get("pdl_context", DependentContext([]))
42+
}
4043

4144
if "pdl_model_default_parameters" not in scope:
4245
scope["pdl_model_default_parameters"] = get_default_model_parameters()

0 commit comments

Comments
 (0)