Support for f-strings in Python->Laurel translation + bind variables introduced by exception handlers#595
Open
ssomayyajula wants to merge 21 commits intomainfrom
Open
Support for f-strings in Python->Laurel translation + bind variables introduced by exception handlers#595ssomayyajula wants to merge 21 commits intomainfrom
ssomayyajula wants to merge 21 commits intomainfrom
Conversation
Translate Python with statements to __enter__/__exit__ instance calls. For each withitem, a manager variable is declared from the context expression, __enter__ is called (binding the result if 'as VAR' is present), the body is translated, then __exit__ is called. Also fix translateType to recognize user-defined composite types and return UserDefined instead of falling through to AnyTy. This was a pre-existing gap that caused type unification errors when composite-typed variables flowed through translateType. Add test covering with...as, with (no as), and multiple context managers.
The direct-to-Core path (pyAnalyze) does not support with statements, so skip this test for the non-laurel SARIF runner.
- FormattedValue: convert inner expr to string via to_string_any - JoinedStr: concatenate all parts using PAdd (same as string +) - Interpolation/TemplateStr (Python 3.14+ t-strings): fall through to Hole - inferExprType: return Str for JoinedStr and FormattedValue - Add f-string test cases to test_strings.py
- Revert test_strings.py to original (core-compatible) content - Add test_fstrings.py with f-string test cases - Add empty expected_laurel/test_fstrings.expected (to be populated from CI)
…trata into feat-python-formatted-value
- Declare 'as' variable (e.g. 'except Exception as e') as a LocalVariable in the handler so it is in scope for Laurel-to-Core - Translate the exception type annotation for the variable's type - Update test_missing_models expected output (new call_print_arg assertions from f-string translation of print arguments)
Contributor
|
Could you resolve the conflict? |
F-string parts are always strings, so use well-typed str.concat via StrConcat operator instead of generic PAdd which generates massive type-dispatch branches in SMT.
…lify exception handler FormattedValue now packs composite-typed values (e.g. PythonError) into from_ClassInstance with their fields as DictStrAny, enabling to_string_any to accept them. Also removes duplicate LocalVariable declaration in ExceptHandler since hoisting already handles exception variable binding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes:
Handle f-strings in Python->Laurel translation
Bind exception variables fromFixed in PR 609except ... as ehandlers as LocalVariable declarations in Laurel, so they are inscope when referenced in f-strings or other expressions within the handler body.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.