Closed dwiel closed 3 years ago
I'm having the same issue! Sharing what i have tested so far.
from talon import app, Module, Context, actions, ui
from talon.voice import Capture
module = Module()
module.list("value", "some values")
@module.capture
def value(m) -> str: """print some value"""
context = Context()
context.lists["self.value"] = []
@context.capture(rule="{self.value}")
def value(m) -> str:
print("value: ", m.value)
return m.value
@module.action_class
class Actions:
def update(k: str, v: str) -> str:
"Updates the list"
context.lists["self.value"].update({k: v})
I have a command declared as:
[value] <user.value>: insert(value)
I can trigger the action from the repl: actions.user.update("test", "something")
saying "test" will print "something", but only after having switched applications.
One possible workaround for some use cases is to listen for a ui event and notify the list. This only works if for example the title changes regularly as it does for me when using vim and changing between modes, but it's not ideal.
def ui_event(event, argument):
print("Notifying list update")
context.lists = context.lists
ui.register('', ui_event)
which version of talon have you most recently reproduced this in? does it repro in both the current public and the current beta?
I just confirmed this is the case on the Talon Version: 0.1.2-95-gce22f90
. Only after switching context can I actually run the 'test' command. I only tried to repro @Gauteab's test
I just realized the underlying issue here. In-place mutation of word lists on contexts isn't supported. You're supposed to manage the list contents yourself and update the whole list at once.
Good:
ctx.lists['self.value'] = ['1', '2', '3']
ctx.lists['self.value'] = {'a': 'b', 'c': 'd'}
Bad:
ctx.lists['self.value']['a'] = 'b'
ctx.lists['self.value'] |= {'a': 'b'}
ctx.lists['self.value'].update({'a': 'b'})
The next beta release will throw this error for the Bad variant:
TypeError: Cannot mutate word lists. You must set the whole list at once.
When I run this action, I can see that an additional entry has been added to the list as expected, but I can't get it to trigger in any rule which uses that new entry. Original entries in that list continue to work fine.