-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Renaming idents, second stage: use proper renaming in scalc and Python #666
Conversation
CI fails because of a bug in the python printer, independent from this (an ident became longer, which triggered a line cut at a point that python doesn't like) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outputs look much better overall. The surrounding parenthesis in the generated python code is unfortunate but, at least, it works.
Same remark as for #664: I'm not sufficiently knowledgeable for super relevant remarks but based on the output, it looks good to me.
it's not very satisfying, but we make it pass through renaming for now. A better approach could be to make this special handling structural, or to have something more specific than an id to hold onto.
Statements are often flattened, in which case their idents need to be conflict-free. We pass along the renaming context to handle this.
matches can bind, but switches cannot, so we can assume the switch argument should always be bound to a name ; this allow the intermediate variable to be better renamed.
I can't find where the line cut triggering the error at https://github.com/CatalaLang/catala/actions/runs/10304111306/job/28522272547?pr=666 came from: ``` /home/ocaml/french-law/_python_venv/lib/python3.12/site-packages/french_law/Aides_logement.py:27785: error: invalid syntax [syntax] ``` the file at this point contains: ``` def traitement_aide_finale_montee_en_charge_saint_pierre_miquelon1( aide_finale4:Money): → traitement_aide_finale_montee_en_charge_saint_pierre_miquelon4 = handle_exceptions( [], [] ) ``` This workaround adds parens after `=`, which ensures the syntax will be correct.
Thanks @vincent-botbol Co-authored-by: vbot <[email protected]>
This completes (and builds on top of) #664 :
renaming is now in its own module, customisable enough, and called with the proper options for each backend. In particular, this simplifies the generated Python code, while being at the same time much more reliable.