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

--disallow-any-generics generates spurious messages #7077

Closed
msullivan opened this issue Jun 27, 2019 · 6 comments · Fixed by #7100
Closed

--disallow-any-generics generates spurious messages #7077

msullivan opened this issue Jun 27, 2019 · 6 comments · Fixed by #7100
Labels
bug mypy got something wrong priority-0-high

Comments

@msullivan
Copy link
Collaborator

In certain cases, --disallow-any-generics will generate an error message in the file where a type alias is used with the line number at which the type alias is defined.

For example

[case testDisallowAnyGenericsMessages]
# mypy: disallow-any-generics
from a import B
x: B

[file a.py]
from typing import TypeVar, List

T = TypeVar('T')

A = List[T]
B = A

[builtins fixtures/list.pyi]

generates the error main:6: error: Missing type parameters for generic type. main:6 is not a line that appears.

The error here is line 6 of a.py, B = A, though that is not an error in this case because disallow-any-generics is not specified for that file. It is triggered by line 3 of main, but reporting an error there would also be wrong because there is nothing wrong with line 3 of main, just with the definition of B. (And there is nothing that can be fixed at that call site, because B is not generic!).

I'm marking this as high priority because disallow-any-generics is a super important option that we I think we should make a default once it is fixed.

@ilevkivskyi
Copy link
Member

In general it seems to me we should prohibit using types as contexts for errors in general (or make file name part of error context).

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 27, 2019

I think that types are probably fine as error contexts in the semantic analyzer.

ilevkivskyi added a commit that referenced this issue Jul 3, 2019
Fixes #7077

The logic of the fix is quite straightforward: emit the error immediately when we fix an instance type, and not in a traversal after the main pass. Note that I fix this only for the new analyser, because the old one will be anyway deprecated soon.

This causes a bit of code churn because we need to pass the flags to several functions, but the logic should not change much. I didn't add many new tests, since we have a bunch of existing tests. It would probably make sense to play with this, suggestions for more tests are very welcome.
@happy2mylife
Copy link

happy2mylife commented Jul 6, 2019

Sorry, I have problem.

from typing import TypeVar, Generic, Any

T = TypeVar('T', bound='Test')
class Test(Generic[T]):
    def output(self):
        print("out")

test.py:3: error: Missing type parameters for generic type

I can't understand this error.

@hibix43
Copy link

hibix43 commented Jul 7, 2019

I also have same problem with @happy2mylife .

@happy2mylife
Copy link

Is this problem not solved yet? @msullivan

@JelleZijlstra
Copy link
Member

You probably need to put Test[Any] in your bound. This example looks rather different from the original one in this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants