Kivy: Properties within f-string not binded

Created on 11 May 2019  路  3Comments  路  Source: kivy/kivy

Versions

  • Python: 3.7.3
  • OS: ArchLinux (kernel 5.0.11)
  • Kivy: 1.10.1
  • Kivy installation method: Poetry (pip)

Description

Within KV files, the syntax "{}".format(object.property) binds correctly, but the syntax f"{object.property}" does not.

In the example below:

  • the first label is just a raw binding,
  • the second label uses the format() function,
  • the third label uses a f-string.

Code and Logs

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()

image

Feature

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.

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings