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

context lists don't update grammar when changed by an action #118

Closed
dwiel opened this issue Sep 18, 2020 · 4 comments
Closed

context lists don't update grammar when changed by an action #118

dwiel opened this issue Sep 18, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@dwiel
Copy link

dwiel commented Sep 18, 2020

    def openai_new_tag(text: str):
        """create a new openai tag"""
        ctx.lists["user.openai_tag"][text] = text
        print(ctx.lists["user.openai_tag"])

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.

@Gauteab
Copy link

Gauteab commented Sep 18, 2020

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)

@lunixbochs
Copy link

which version of talon have you most recently reproduced this in? does it repro in both the current public and the current beta?

@lunixbochs lunixbochs added the bug Something isn't working label Nov 2, 2020
@fidgetingbits
Copy link

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

@lunixbochs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants