Skip to content

"Missing type parameters for generic type" indicates wrong line/file combination #6112

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
AvdN opened this issue Dec 28, 2018 · 3 comments
Closed

Comments

@AvdN
Copy link

AvdN commented Dec 28, 2018

Bug while using mypy 0.650

In my source code I have to be Python2 and 3 compatible (this is the ruamel.yaml package) and I had a working definition for StreamType that boils down to this:

from StringIO import StringIO

if False:  # MYPY
    from typing import Any, Dict, Optional, List, Union, BinaryIO, IO, Text 

    StreamType = Union[BinaryIO, IO[str], StringIO]

(actually this is on line 120 of compat.py)

This started to give me an error:

ruamel/yaml/compat.py:120: error: Missing type parameters for generic type

As so often with mypy, I had no clue why I now got this error and how to fix it properly, so I added # type: ignore at the end of that line. I got distracted fixing some real code issues and the next day
I was trying to fix one of many, many more mypy reported errors, soon hitting one in util.py:

ruamel/yaml/util.py:120: error: Missing type parameters for generic type

And that line happens to have no code.

I added # type: ignore to line 119 in util.py (which has code), but the error would not go away. I started decimating the file to find at which line the actual problem occurred and the error stayed at line 120, even though the file had less than 40 lines. Once I hit line 16 and removed the line

    from .compat import StreamTextType  # NOQA

and realising that StreamTextType is derived from StreamType, I realised that the 120 was the line number from the compat.py file.

As I understand it the # type: ignore doesn't survive an import. Addign # type: ignore to the import line in util.py will add a note about unused type: ignore`` and the error persists.

For now I have to simplify the definition of StreamType to Any to be able to proceed as that fixed all the follow up errors ( 30+ of them), and I could revert the "fixes" for those that I implemented.

Although I am interested in the proper definition of StreamType, the bug with the line number being of a different file major, as it is extremely time consuming to find.

@ilevkivskyi
Copy link
Member

Could you please provide a self-contained repro?

Also, please note that StringIO.StringIO is generic in typeshed, so you should write StringIO[str] or StringIO[unicode] or similar. Or maybe you actually wanted typing.TextIO?

@AvdN
Copy link
Author

AvdN commented Dec 28, 2018

Here is a rather minimal set of test files and some commands with output.
The 40, in the last line, doesn't make sense at all, as the wc indicates
there are only 16 lines in that file.

$ mypy --version
mypy 0.650
$ uname -a
Linux pooh.mnt.org 4.1.4-040104-generic #201508031330 SMP Mon Aug 3 17:32:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ wc -l util.py
16 util.py
$ mypy --py2 --strict --follow-imports silent compat.py util.py
compat.py:40: error: Missing type parameters for generic type
util.py:40: error: Missing type parameters for generic type

a.zip

@ilevkivskyi
Copy link
Member

This is a duplicate of #7077 (or rather vice-versa but the other issue has a simpler repro).

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