Skip to content

Error message about invalid TypeVar definition is cryptic #1573

Open
@berdario

Description

@berdario

With the following

from itertools import groupby
from typing import Iterator, Iterable, TypeVar, Callable, Tuple, Any

X, Key = TypeVar('X'), TypeVar('Key')
def sorted_groupby(sequence: Iterable[X], key: Callable[[X], Key]) -> Iterator[Tuple[Key, Iterator[X]]]:
    return groupby(sorted(sequence, key=key), key=key)

You'll get

a.py:4: error: "object" not callable
a.py: note: In function "sorted_groupby":
a.py:5: error: Invalid type "a.X"
a.py:5: error: Invalid type "a.Key"

It would be nice if TypeVars didn't have restrictions compared to the full python syntax that can otherwise be used in non-typechecked code

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions