Skip to content

v_args decorator retval type hint isn't correct, might as well be removed #1579

@Kache

Description

@Kache

Describe the bug

The return value type hint for v_args() isn't fully correct

def v_args(inline: bool = False, meta: bool = False, tree: bool = False, wrapper: Optional[Callable] = None) -> Callable[[_DECORATED], _DECORATED]:

When -> Callable[[_DECORATED], _DECORATED] is removed entirely, i.e. the line changed to:

def v_args(inline: bool = False, meta: bool = False, tree: bool = False, wrapper: Optional[Callable] = None):

my typechecker (pyright/basedpyright, i.e. pylance from VSCode) properly infers the return type of transform()

To Reproduce

from lark import Transformer, v_args, Token, Tree

@v_args(meta=True)
class Foo(Transformer[Token, str]):
    def __init__(self):
        super().__init__()

    def foo(self, meta, args):
        return 'baz'


bar = Foo().transform(Tree('foo', []))
assert bar == 'baz'

with -> Callable[[_DECORATED], _DECORATED], type inference breaks and bar is considered Any | Unknown

without, bar is correctly considered str

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions