From 0585e35719ecf38c691caeef0cfa1b2ebf717356 Mon Sep 17 00:00:00 2001 From: Eric Shi Date: Mon, 16 Sep 2024 21:39:35 -0700 Subject: [PATCH] Fix codegen issue with docstrings Codegen should now avoid creating variables from docstrings. --- CHANGELOG.md | 1 + warp/codegen.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43844ac5..375f7702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Fix array in-place op (`+=`, `-=`) adjoints to compute gradients correctly in the backwards pass. - `wp.sim.Model.edge_indices` now includes boundary edges - Allow shadowing builtin functions ([GH-308](https://github.com/NVIDIA/warp/issues/308)) +- Fix a bug in which Python docstrings would be created as local function variables in generated code. ## [1.3.3] - 2024-09-04 diff --git a/warp/codegen.py b/warp/codegen.py index ee1517ed..880b3bf2 100644 --- a/warp/codegen.py +++ b/warp/codegen.py @@ -1493,6 +1493,9 @@ def end_while(adj): def emit_FunctionDef(adj, node): for f in node.body: + # Skip variable creation for standalone constants, including docstrings + if isinstance(f, ast.Expr) and isinstance(f.value, ast.Constant): + continue adj.eval(f) if adj.return_var is not None and len(adj.return_var) == 1: