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

Error message about invalid TypeVar definition is cryptic #1573

Open
berdario opened this issue May 24, 2016 · 2 comments
Open

Error message about invalid TypeVar definition is cryptic #1573

berdario opened this issue May 24, 2016 · 2 comments

Comments

@berdario
Copy link

berdario commented May 24, 2016

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

@gvanrossum
Copy link
Member

gvanrossum commented May 24, 2016 via email

@ilevkivskyi
Copy link
Member

The error message could be better in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants