Skip to content

Commit 8690547

Browse files
keyboardDrummer-botshigoelfabiomadge
authored
fix: add missing opt parameter to Laurel print declaration (#971)
PR requested and agreed on by @olivier-aws ## Summary The Laurel `print` procedure declaration in `PythonRuntimeLaurelPart.lean` was missing the `opt` parameter that models Python's variadic `*objects`. Without it, a call like `print("a", "b")` would be handled differently in the Laurel path vs the Core path, since positional arguments would shift. ## Changes 1. **`Strata/Languages/Python/PythonRuntimeLaurelPart.lean`** — Added `opt : Any` parameter to the `print` declaration, matching the Core declaration's parameter list: ``` // Before procedure print(msg : Any, sep : Any, end : Any, file : Any, flush : Any) returns (); // After procedure print(msg : Any, opt : Any, sep : Any, end : Any, file : Any, flush : Any) returns (); ``` 2. **`StrataTest/Languages/Python/VerifyPythonTest.lean`** — Added a test exercising `print` with multiple positional arguments (`print()`, `print("a")`, `print("a", "b")`, `print("a", "b", "c")`) and combinations with keyword arguments (`sep`, `end`, `flush`). Per @olivier-aws's guidance, the parameter types are kept as `Any` (not changed to match Core's `StrOrNone`/`BoolOrNone`/`AnyOrNone`). Both the source and test files build successfully with `lake build`. Fixes #941 --------- Co-authored-by: keyboardDrummer-bot <keyboardDrummer-bot@users.noreply.github.com> Co-authored-by: Shilpi Goel <shigoel@gmail.com> Co-authored-by: Fabio Madge <fmadge@amazon.com>
1 parent e39bee1 commit 8690547

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Strata/Languages/Python/PythonRuntimeLaurelPart.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ procedure test_helper_procedure(req_name : Any, opt_name : Any) returns (ret: An
10731073
assume (Error..isNoError(maybe_except)) // summary "assume_maybe_except_none"
10741074
};
10751075

1076-
procedure print(msg : Any, sep : Any, end : Any, file : Any, flush : Any) returns ();
1076+
procedure print(msg : Any, opt : Any, sep : Any, end : Any, file : Any, flush : Any) returns ();
10771077

10781078
#end
10791079

StrataTest/Languages/Python/VerifyPythonTest.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,22 @@ def test() -> None:
505505
if diags.size ≠ 0 then
506506
throw <| .userError s!"Expected 0 diagnostics, got {diags.size}: {diags.map (·.message)}"
507507

508+
-- print() with multiple positional arguments exercises the opt parameter.
509+
#guard_msgs in
510+
#eval withPython (warnOnSkip := false) fun pythonCmd => do
511+
let program :=
512+
"def main() -> None:
513+
print()
514+
print(\"a\")
515+
print(\"a\", \"b\")
516+
print(\"a\", \"b\", \"c\")
517+
print(\"a\", \"b\", sep=\",\", end=\"\\n\", flush=True)
518+
print(\"x\", \"y\", \"z\", sep=\" \")
519+
"
520+
let diags ← processPythonFile pythonCmd (stringInputContext "test.py" program)
521+
if diags.size ≠ 0 then
522+
throw <| .userError s!"Expected 0 diagnostics, got {diags.size}: {diags.map (·.message)}"
523+
508524
-- PreludeInfo.ofLaurelProgram should strip the $in_ prefix from parameter
509525
-- names so that cross-module keyword argument calls use the original names.
510526
#guard_msgs in

StrataTest/Languages/Python/expected_laurel/test_class_decl.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_class_decl.py(9, 4): ✅ pass - callElimAssert_requires_13
1+
test_class_decl.py(9, 4): ✅ pass - callElimAssert_requires_15
22
test_class_decl.py(8, 0): ✅ pass - postcondition
33
test_class_decl.py(13, 0): ✅ pass - ite_cond_calls_Any_to_bool_0
44
DETAIL: 3 passed, 0 failed, 0 inconclusive

0 commit comments

Comments
 (0)