Skip to content

Better message for invalid types like (int, str) #4173

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

Closed
JukkaL opened this issue Oct 27, 2017 · 4 comments
Closed

Better message for invalid types like (int, str) #4173

JukkaL opened this issue Oct 27, 2017 · 4 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 27, 2017

The error message "Invalid tuple literal type" isn't very helpful if a user writes (int, str) instead of Tuple[int, str].

Example:

from typing import List

def f():
    # type: () -> (int, str)   # Invalid tuple literal type
    return (1, 'x')

A better message could be something like this:

program.py:3: error: Syntax error in type annotation
program.py:3:note: Suggestion: Use "Tuple[T1, ..., Tn]" instead of "(T1, ..., Tn)"

#4172 is closely related.

@elliott-beach
Copy link
Contributor

Interested. Are you suggesting literally (T1, ..., Tn) or substituting in the types values used, as in, (int, str) in the error message? I think the later makes more sense, if slightly more complex to implement.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Feb 20, 2018

Are you suggesting literally (T1, ..., Tn) or substituting in the types values used, as in, (int, str) in the error message? I think the later makes more sense, if slightly more complex to implement.

Just literal (T1, ..., Tn) (or something similar) would be enough.

@Hnasar
Copy link
Contributor

Hnasar commented Mar 20, 2018

Came across this today when I accidentally had:

def foo(
    arg1,  # type: int,
    arg2,  # type: str
):  # type (...) -> None
    pass

The lint was on the first line of the function definition, def foo, but the problem was an errant comma on arg1.

@emmatyping
Copy link
Member

@Hnasar that is technically #4172, but these are, as Jukka said previously, closely related.

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

4 participants