Skip to content

Commit 6bf6d07

Browse files
Fix codegen with keyword
1 parent c2138d8 commit 6bf6d07

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/replit_river/codegen/typing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import keyword
12
from dataclasses import dataclass
23
from typing import NewType, assert_never, cast
34

@@ -165,7 +166,11 @@ def work(
165166
def normalize_special_chars(value: str) -> str:
166167
for char in SPECIAL_CHARS:
167168
value = value.replace(char, "_")
168-
return value.lstrip("_")
169+
value = value.lstrip("_")
170+
# Append underscore to Python keywords (e.g., "from" -> "from_")
171+
if keyword.iskeyword(value):
172+
value = value + "_"
173+
return value
169174

170175

171176
def render_type_expr(value: TypeExpression) -> str:

0 commit comments

Comments
 (0)