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

string.format() with identity-expressions #13126

Open
akaessens opened this issue Apr 22, 2024 · 3 comments · May be fixed by #13128
Open

string.format() with identity-expressions #13126

akaessens opened this issue Apr 22, 2024 · 3 comments · May be fixed by #13128

Comments

@akaessens
Copy link

akaessens commented Apr 22, 2024

With fstrings we can format identity expressions:

a = 1
string = f'@a@'

Positional arguments with string.format()

a = 1
'@0@'.format(a)

In our use case, we want to format strings with identity expressions. We use a native file with meson.get_external_property().
The name property may contain @a@.

string = meson.get_external_property('name', 'default')

string.format() # this should replace identity expressions, i.e. @a@ -> 1
@QuLogic
Copy link
Member

QuLogic commented Apr 22, 2024

That's get_variable(string), is it not? Edit: actually, I misread, but:

Positional arguments with string.format()

a = 1
'@0@'.format('a')

doesn't produce 1, but a, so I'm not sure about the logic that ends with string.format().

@jpakkane
Copy link
Member

jpakkane commented Jun 1, 2024

doesn't produce 1, but a

Which is what should happen, right? Otherwise your strings get expanded into weird values if they happen to contain names of defined variables.

@akaessens
Copy link
Author

akaessens commented Jun 1, 2024

doesn't produce 1, but a

Which is what should happen, right? Otherwise your strings get expanded into weird values if they happen to contain names of defined variables.

It was a bug in my original message example, I fixed it now.

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 a pull request may close this issue.

3 participants