talonvoice / talon

Issue Tracker for the main Talon app
85 stars 0 forks source link

TalonScript TypeError when using `X | Y`-style union types for action parameter type hints #634

Closed pokey closed 9 months ago

pokey commented 1 year ago

In the following code:

test_type.py

from talon import Module

mod = Module()

@mod.action_class
class Actions:
    def foo_bar(baz: str | int):
        """foo bar"""
        print(baz)

test_type.talon

test type: user.foo_bar("baz")

Saying "test type" results in the following error:

2023-10-05 11:45:03.468 ERROR TalonScript TypeError in: /Users/pokey/.talon/user/pokey_talon/test_type.talon:1
2023-10-05 11:45:03.469 ERROR Line 1: user.foo_bar(baz: str | int)
2023-10-05 11:45:03.469 ERROR Line 1:   parameter 1 (baz) expects type str | int, got <class 'str'>

Note that if the type signature is changed to Union[str, int], there is no error raised.

Fwiw, this style of union type was introduced in Python 3.10; see PEP 604 for more info.

Possibly related: https://github.com/talonvoice/talon/issues/415

lunixbochs commented 9 months ago

fixed in next beta