Skip to content

Rename Any_to_bool to python_is_truthy and add construct support#669

Draft
joehendrix wants to merge 2 commits intomainfrom
jhx/python-constructs
Draft

Rename Any_to_bool to python_is_truthy and add construct support#669
joehendrix wants to merge 2 commits intomainfrom
jhx/python-constructs

Conversation

@joehendrix
Copy link
Copy Markdown
Contributor

Summary

  • Rename Any_to_boolpython_is_truthy: More descriptive name for the Python truthiness function. Updated in prelude definition, PAnd/POr callers, and all PythonToLaurel call sites (IfThenElse, While, Assert).
  • New construct support: PPow (** operator), FormattedValue (f-string interpolation), Slice expressions — all previously threw "unsupported construct" errors.
  • Exception var typing fix: Error variables in except clauses now use Any type instead of PythonError (a Composite type), fixing type mismatches in the Any-typed pipeline.
  • AugAssign cleanup: Unsupported augmented assignment operators now throw explicit errors instead of silently emitting Hole.

Test plan

  • lake build passes cleanly
  • All AnalyzeLaurelTest cases pass (including tests that use try/except)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

🤖 Generated with Claude Code

Rename the truthiness function from Any_to_bool to python_is_truthy in
the prelude and all call sites (PAnd, POr, IfThenElse, While, Assert).

Add support for previously unsupported Python constructs:
- PPow (** operator)
- FormattedValue (f-string interpolation)
- Slice expressions

Fix exception variable typing: use Any instead of PythonError (which is
a Composite type incompatible with the Any-typed exception handling).

Refactor AugAssign to throw on unsupported operators instead of silently
emitting Hole.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joehendrix joehendrix requested a review from a team March 26, 2026 06:49
@joehendrix joehendrix marked this pull request as draft March 26, 2026 07:04
Add 6 end-to-end tests exercising the new construct translations:
- test_ternary.py: ternary conditional with python_is_truthy
- test_pow_operator.py: ** operator (PPow)
- test_fstring.py: f-string interpolation (FormattedValue)
- test_slice.py: list slicing (Slice)
- test_augassign.py: augmented assignment (+=)
- test_except_var_usage.py: exception variable typed as Any

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant