Within KV files, the syntax "{}".format(object.property)
binds correctly, but the syntax f"{object.property}"
does not.
In the example below:
format()
function,f-string
.from kivy.app import App
from kivy.lang import Builder
kv = r"""
BoxLayout:
orientation: 'vertical'
TextInput:
id: text_input
text: "foo"
Label:
text: text_input.text
Label:
text: "text input value using `format()`: {}".format(text_input.text)
Label:
text: f"text input value using f-string: {text_input.text}"
"""
class SandboxApp(App):
def build(self):
return Builder.load_string(kv)
def main():
SandboxApp().run()
if __name__ == '__main__':
main()
I took a quick look and python ast has a new node for f-strings (called FormattedValue
). This means that we should be able to implement using the ast parser.
If I have time in the future, I plan to update the kv compiler branch to drop the python syntax and instead stick only with traditional kv syntax and try to get that into kivy. Then it should be easy to add support for this in the ast parsing step.
Duplicate of #6108?
closing as duplicate of #6108
Most helpful comment
I took a quick look and python ast has a new node for f-strings (called
FormattedValue
). This means that we should be able to implement using the ast parser.If I have time in the future, I plan to update the kv compiler branch to drop the python syntax and instead stick only with traditional kv syntax and try to get that into kivy. Then it should be easy to add support for this in the ast parsing step.