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

Unhelpful message "invalid type" #5586

Closed
ruuda opened this issue Sep 7, 2018 · 2 comments
Closed

Unhelpful message "invalid type" #5586

ruuda opened this issue Sep 7, 2018 · 2 comments

Comments

@ruuda
Copy link

ruuda commented Sep 7, 2018

Consider the following file:

from tempfile import SpooledTemporaryFile

def make_file() -> SpooledTemporaryFile:
    return SpooledTemporaryFile()

temp_file = make_file()

When I typecheck this, I get

invalid.py:3: error: Invalid type "tempfile.SpooledTemporaryFile"
invalid.py:6: error: Need type annotation for 'temp_file'

This message is not helpful; what does it mean for a type to be "invalid", and why is SpooledTemporaryFile invalid?

If I add a type annotation as suggested by the second message, I get the "invalid" message twice:

invalid.py:3: error: Invalid type "tempfile.SpooledTemporaryFile"
invalid.py:6: error: Invalid type "tempfile.SpooledTemporaryFile"

I am using Mypy 0.620.

@ruuda
Copy link
Author

ruuda commented Sep 7, 2018

Looking into this, SpooledTemporaryFile is a function in typeshed, but it’s a class in my /usr/lib/python3.6/tempfile.py. Is the typeshed annotation wrong?

In any case, it would be nice if the error message could indicate that SpooledTemporaryFile is not a valid type because it is a function, rather than just saying "invalid type".

@ilevkivskyi
Copy link
Member

For poor error message, this is a duplicate of #4030

For the signature, yes, report this to typeshed issue tracker.

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

No branches or pull requests

2 participants