-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add more details for "Invalid type" errors #7166
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
Changes from 4 commits
1a704cb
093ca81
b92227d
1b8514d
f3cf9f2
575ebd2
2f7c69a
ef70883
69178d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4833,12 +4833,13 @@ reveal_type(Arc1[MyDestr]()) # N: Revealed type is '__main__.Arc1[__main__.MyDe | |
[typing fixtures/typing-full.pyi] | ||
|
||
[case testSixMetaclassErrors] | ||
# flags: --new-semantic-analyzer | ||
import six | ||
class M(type): pass | ||
class A(object): pass | ||
def f() -> type: return M | ||
class C1(six.with_metaclass(M), object): pass # E: Invalid base class | ||
class C2(C1, six.with_metaclass(M)): pass # E: Invalid base class | ||
class C1(six.with_metaclass(M), object): pass # E: Invalid base class "six.with_metaclass": Unsupported dynamic base class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, this could be shortened to |
||
class C2(C1, six.with_metaclass(M)): pass # E: Invalid base class "six.with_metaclass": Unsupported dynamic base class | ||
class C3(six.with_metaclass(A)): pass # E: Metaclasses not inheriting from 'type' are not supported | ||
@six.add_metaclass(A) # E: Argument 1 to "add_metaclass" has incompatible type "Type[A]"; expected "Type[type]" \ | ||
# E: Metaclasses not inheriting from 'type' are not supported | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,32 +69,34 @@ if int(): | |
(f(b=object())) # E:6: Unexpected keyword argument "b" for "f" | ||
|
||
[case testColumnInvalidType] | ||
# flags: --new-semantic-analyzer | ||
from typing import Iterable | ||
|
||
bad = 0 | ||
|
||
def f(x: bad): # E:10: Invalid type "__main__.bad" | ||
y: bad # E:8: Invalid type "__main__.bad" | ||
def f(x: bad): # E:10: Invalid type "__main__.bad": Cannot use variable as type | ||
y: bad # E:8: Invalid type "__main__.bad": Cannot use variable as type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like above, this could be shortened to |
||
|
||
if int(): | ||
def g(x): # E:5: Invalid type "__main__.bad" | ||
def g(x): # E:5: Invalid type "__main__.bad": Cannot use variable as type | ||
# type: (bad) -> None | ||
y = 0 # type: bad # E:9: Invalid type "__main__.bad" | ||
y = 0 # type: bad # E:9: Invalid type "__main__.bad": Cannot use variable as type | ||
|
||
z: Iterable[bad] # E:13: Invalid type "__main__.bad" | ||
h: bad[int] # E:4: Invalid type "__main__.bad" | ||
z: Iterable[bad] # E:13: Invalid type "__main__.bad": Cannot use variable as type | ||
h: bad[int] # E:4: Invalid type "__main__.bad": Cannot use variable as type | ||
|
||
[case testColumnInvalidType_python2] | ||
# flags: --new-semantic-analyzer | ||
from typing import Iterable | ||
|
||
bad = 0 | ||
|
||
if int(): | ||
def g(x): # E:5: Invalid type "__main__.bad" | ||
def g(x): # E:5: Invalid type "__main__.bad": Cannot use variable as type | ||
# type: (bad) -> None | ||
y = 0 # type: bad # E:9: Invalid type "__main__.bad" | ||
y = 0 # type: bad # E:9: Invalid type "__main__.bad": Cannot use variable as type | ||
|
||
z = () # type: Iterable[bad] # E:5: Invalid type "__main__.bad" | ||
z = () # type: Iterable[bad] # E:5: Invalid type "__main__.bad": Cannot use variable as type | ||
|
||
[case testColumnFunctionMissingTypeAnnotation] | ||
# flags: --disallow-untyped-defs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1720,6 +1720,7 @@ def Arg(x, y): pass | |
F = Callable[[Arg(int, 'x')], int] # E: Invalid argument constructor "__main__.Arg" | ||
|
||
[case testCallableParsingFromExpr] | ||
# flags: --new-semantic-analyzer | ||
from typing import Callable, List | ||
from mypy_extensions import Arg, VarArg, KwArg | ||
import mypy_extensions | ||
|
@@ -1737,12 +1738,12 @@ J = Callable[[VarArg(), KwArg()], int] # ok | |
K = Callable[[VarArg(), int], int] # E: Required positional args may not appear after default, named or var args | ||
L = Callable[[Arg(name='x', type=int)], int] # ok | ||
# I have commented out the following test because I don't know how to expect the "defined here" note part of the error. | ||
# M = Callable[[Arg(gnome='x', type=int)], int] E: Invalid type alias E: Unexpected keyword argument "gnome" for "Arg" | ||
# M = Callable[[Arg(gnome='x', type=int)], int] E: Invalid type alias: cannot interpret right hand side as a type E: Unexpected keyword argument "gnome" for "Arg" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bikeshedding: |
||
N = Callable[[Arg(name=None, type=int)], int] # ok | ||
O = Callable[[List[Arg(int)]], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type "Type[List[Any]]" is not generic and not indexable | ||
O = Callable[[List[Arg(int)]], int] # E: Invalid type alias: cannot interpret right hand side as a type # E: Value of type "int" is not indexable # E: Type expected within [...] # E: The type "Type[List[Any]]" is not generic and not indexable | ||
P = Callable[[mypy_extensions.VarArg(int)], int] # ok | ||
Q = Callable[[Arg(int, type=int)], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "type" | ||
R = Callable[[Arg(int, 'x', name='y')], int] # E: Invalid type alias # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "name" | ||
Q = Callable[[Arg(int, type=int)], int] # E: Invalid type alias: cannot interpret right hand side as a type # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "type" | ||
R = Callable[[Arg(int, 'x', name='y')], int] # E: Invalid type alias: cannot interpret right hand side as a type # E: Value of type "int" is not indexable # E: "Arg" gets multiple values for keyword argument "name" | ||
|
||
[builtins fixtures/dict.pyi] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2180,6 +2180,7 @@ tmp/b.py:1: error: Module 'c' has no attribute 'x' | |
tmp/b.py:1: error: Module 'c' has no attribute 'x' | ||
|
||
[case testCacheDeletedAfterErrorsFound2] | ||
# flags: --new-semantic-analyzer | ||
import a | ||
[file a.py] | ||
from b import x | ||
|
@@ -2195,9 +2196,9 @@ from b import x | |
1 + 1 | ||
[out] | ||
[out2] | ||
tmp/b.py:2: error: Invalid type "c.C" | ||
tmp/b.py:2: error: Invalid type "c.C": Cannot use function as type, use Callable[...] or a protocol instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, the first part could be shortened to
|
||
[out3] | ||
tmp/b.py:2: error: Invalid type "c.C" | ||
tmp/b.py:2: error: Invalid type "c.C": Cannot use function as type, use Callable[...] or a protocol instead | ||
|
||
[case testCacheDeletedAfterErrorsFound3] | ||
import a | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding: this error message could be shortened down to
Module "mock" is not valid as a type
without loss of clarity, I think.