Skip to content

Fix codegen with from keyword#177

Merged
daweifeng-replit merged 3 commits intomainfrom
fix-from-key-word
Mar 9, 2026
Merged

Fix codegen with from keyword#177
daweifeng-replit merged 3 commits intomainfrom
fix-from-key-word

Conversation

@daweifeng-replit
Copy link
Contributor

Why

For schema with from and to properties. from is a Python reserved keyword, and the river-python codegen was generating invalid Python like:

class Rewrites(TypedDict):
    from: NotRequired[str | None]   # SyntaxError!

What changed

  • src/replit_river/codegen/typing.py — Added import keyword and extended normalize_special_chars to append _ to Python keywords (e.g., from -> from_). The existing alias logic in client.py already handles setting Field(alias="from") for BaseModel when the field name is normalized, so no changes needed there.

  • tests/v1/codegen/test_input_special_chars.py — Added two new tests (test_python_keyword_field_names_basemodel and test_python_keyword_field_names_typeddict) that verify the codegen produces valid Python when schema fields use reserved keywords like from, class, and import.

Test plan

Added new tests

@daweifeng-replit daweifeng-replit requested a review from a team as a code owner March 9, 2026 21:33
@daweifeng-replit daweifeng-replit requested review from Monkatraz and removed request for a team March 9, 2026 21:33
@daweifeng-replit daweifeng-replit merged commit af775fc into main Mar 9, 2026
3 checks passed
@daweifeng-replit daweifeng-replit deleted the fix-from-key-word branch March 9, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants