@@ -256,12 +256,28 @@ class MontyRepl:
256256 * ,
257257 script_name : str = 'main.py' ,
258258 limits : ResourceLimits | None = None ,
259+ type_check : bool = False ,
260+ type_check_stubs : str | None = None ,
259261 dataclass_registry : list [type ] | None = None ,
260262 ) -> Self :
261263 """
262264 Create an empty REPL session ready to receive snippets via `feed_run()`.
263265
264266 No code is parsed or executed at construction time.
267+
268+ Arguments:
269+ script_name: Name used in tracebacks and error messages
270+ limits: Optional resource limits configuration
271+ type_check: Whether to type-check each snippet before execution.
272+ When enabled, each `feed_run`/`feed_run_async`/`feed_start` call
273+ runs static type checking before executing the code, and each
274+ successfully executed snippet is appended to the accumulated
275+ context used for type-checking subsequent snippets.
276+ type_check_stubs: Optional stub code providing type declarations for
277+ variables and functions available in the REPL, e.g. input variable
278+ types or external function signatures.
279+ dataclass_registry: Optional list of dataclass types to register for proper
280+ isinstance() support on output.
265281 """
266282
267283 @property
@@ -273,6 +289,24 @@ class MontyRepl:
273289 Register a dataclass type for proper isinstance() support on output.
274290 """
275291
292+ def type_check (self , code : str , prefix_code : str | None = None ) -> None :
293+ """
294+ Perform static type checking on the given code snippet.
295+
296+ Checks the snippet in isolation using `prefix_code` as stub context.
297+ This does not use the accumulated code from previous `feed_run` calls —
298+ use `prefix_code` to provide any needed declarations.
299+
300+ Arguments:
301+ code: The code to type check
302+ prefix_code: Optional code to prepend before type checking,
303+ e.g. with input variable declarations or external function signatures
304+
305+ Raises:
306+ RuntimeError: If type checking infrastructure fails
307+ MontyTypingError: If type errors are found
308+ """
309+
276310 def feed_run (
277311 self ,
278312 code : str ,
@@ -282,16 +316,27 @@ class MontyRepl:
282316 print_callback : Callable [[Literal ['stdout' ], str ], None ] | None = None ,
283317 mount : MountDir | list [MountDir ] | None = None ,
284318 os : Callable [[str , tuple [Any , ...], dict [str , Any ]], Any ] | None = None ,
319+ skip_type_check : bool = False ,
285320 ) -> Any :
286321 """
287322 Execute one incremental snippet and return its output.
288323
289- When `inputs` is provided, the key-value pairs are injected into
290- the REPL namespace before executing the snippet.
291-
292- When `external_functions` is provided, external function calls and
293- name lookups are dispatched to the provided callables — matching the
294- behavior of `Monty.run(external_functions=...)`.
324+ Arguments:
325+ code: The Python code snippet to execute
326+ inputs: Dict of input values injected into the REPL namespace
327+ before executing the snippet
328+ external_functions: Dict of external function callbacks. When
329+ provided, external function calls and name lookups are
330+ dispatched to the provided callables — matching the behavior
331+ of `Monty.run(external_functions=...)`.
332+ print_callback: Optional callback for print output
333+ mount: Optional filesystem mount(s) to expose inside the sandbox
334+ os: Optional OS access handler for filesystem operations
335+ skip_type_check: When `True`, static type checking is bypassed for
336+ this snippet AND the snippet is NOT appended to the accumulated
337+ type-check context, so later type-checked snippets will not see
338+ any names it defined. Has no effect unless `type_check=True`
339+ was set on the REPL.
295340 """
296341
297342 def feed_run_async (
@@ -302,6 +347,7 @@ class MontyRepl:
302347 external_functions : dict [str , Callable [..., Any ]] | None = None ,
303348 print_callback : Callable [[Literal ['stdout' ], str ], None ] | None = None ,
304349 os : AbstractOS | None = None ,
350+ skip_type_check : bool = False ,
305351 ) -> Coroutine [Any , Any , Any ]:
306352 """
307353 Execute one incremental snippet and return its output with support for async external functions.
@@ -315,6 +361,11 @@ class MontyRepl:
315361 external_functions: Dict of external function callbacks (sync or async)
316362 print_callback: Optional callback for print output
317363 os: Optional OS access handler for filesystem operations
364+ skip_type_check: When `True`, static type checking is bypassed for
365+ this snippet AND the snippet is NOT appended to the accumulated
366+ type-check context, so later type-checked snippets will not see
367+ any names it defined. Has no effect unless `type_check=True`
368+ was set on the REPL.
318369
319370 Returns:
320371 A coroutine that resolves to the output of the snippet
@@ -329,6 +380,7 @@ class MontyRepl:
329380 * ,
330381 inputs : dict [str , Any ] | None = None ,
331382 print_callback : Callable [[Literal ['stdout' ], str ], None ] | None = None ,
383+ skip_type_check : bool = False ,
332384 ) -> FunctionSnapshot | NameLookupSnapshot | FutureSnapshot | MontyComplete :
333385 """
334386 Start executing an incremental snippet, yielding snapshots for external calls.
@@ -343,6 +395,17 @@ class MontyRepl:
343395 including support for async external functions via `FutureSnapshot`.
344396
345397 On completion or error, the REPL state is automatically restored.
398+
399+ Arguments:
400+ code: The Python code snippet to execute
401+ inputs: Dict of input values injected into the REPL namespace
402+ before executing the snippet
403+ print_callback: Optional callback for print output
404+ skip_type_check: When `True`, static type checking is bypassed for
405+ this snippet AND the snippet is NOT appended to the accumulated
406+ type-check context, so later type-checked snippets will not see
407+ any names it defined. Has no effect unless `type_check=True`
408+ was set on the REPL.
346409 """
347410
348411 def dump (self ) -> bytes :
0 commit comments