Skip to content
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

Support class scoped variable lookup in interpolation lambdas (take 2) #45

Conversation

davepeck
Copy link

@davepeck davepeck commented Jul 13, 2024

With these changes, the following code works:

def fstr(*args):
    return "".join(arg if isinstance(arg, str) else arg[0]() for arg in args)

class Example:
    food = "burrito"
    v = fstr"neato {food}"  # prior to this branch, NameError here
    
print(Example.v)  # neato burrito

This PR follows #44 but takes an approach closer to what we want. Interpolation expressions are no longer wrapped in lambdas. compiler_interpolation() and symtable_visit_expr() are both updated to support this. In addition, ste_* flags are set to allow interpolation expressions to see class scope variables.

Copy link
Owner

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davepeck This looks great! Thanks a lot for working on these changes.

I just pushed a commit that slightly improves the code in symtable.c and brings it closer to other cases like this.

Let's merge this!

@lysnikolaou lysnikolaou merged commit 03af022 into lysnikolaou:tag-strings-rebased Jul 15, 2024
2 checks passed
@davepeck
Copy link
Author

slightly improves the code in symtable.c and brings it closer to other cases like this.

Ah, thanks — that's useful for me to see! Glad it wasn't too far off.

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