You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Strange behavior when superclass is an unknown argument #1069
I never get "meth" undefined in superclass. Instead I get two errors on the class definition, Invalid type "cls" and Invalid base class. It is still the case that inside a function annotating the argument with cls: Any doesn't make a difference but at the global level it does. So I think there is still something here, and I'd like to leave this open.
Original example:
(v35) bash-3.2$ cat -n __tmp__.py
1 from typing import Any
2
3 def f(cls):
4 class C(cls):
5 def meth(self):
6 super(C, self).meth()
(v35) bash-3.2$ my __tmp__.py
(v35) bash-3.2$
I think this is silent simply because we suppress all errors inside unannotated functions.
Adding an annotation cls: Any:
(v35) bash-3.2$ cat -n __tmp__.py
1 from typing import Any
2
3 def f(cls: Any):
4 class C(cls):
5 def meth(self):
6 super(C, self).meth()
(v35) bash-3.2$ my __tmp__.py
__tmp__.py:4: error: Invalid type "cls"
__tmp__.py:4: error: Invalid base class
(v35) bash-3.2$
This is like the original but with a slightly different set of errors.
Outside a function:
(v35) bash-3.2$ cat -n __tmp__.py
1 from typing import Any
2
3 cls = ...
4 class C(cls):
5 def meth(self):
6 super(C, self).meth()
(v35) bash-3.2$ my __tmp__.py
__tmp__.py:4: error: Invalid type "__tmp__.cls"
__tmp__.py:4: error: Invalid base class
(v35) bash-3.2$
Outside a function with an added cls: Any annotation:
(v35) bash-3.2$ cat -n __tmp__.py
1 from typing import Any
2
3 cls = ... # type: Any
4 class C(cls):
5 def meth(self):
6 super(C, self).meth()
(v35) bash-3.2$ my __tmp__.py
(v35) bash-3.2$
Activity
elazarg commentedon Apr 3, 2017
I can't reproduce it now.
gvanrossum commentedon Apr 3, 2017
I never get
"meth" undefined in superclass. Instead I get two errors on the class definition,Invalid type "cls"andInvalid base class. It is still the case that inside a function annotating the argument withcls: Anydoesn't make a difference but at the global level it does. So I think there is still something here, and I'd like to leave this open.Original example:
I think this is silent simply because we suppress all errors inside unannotated functions.
Adding an annotation
cls: Any:This is like the original but with a slightly different set of errors.
Outside a function:
Outside a function with an added
cls: Anyannotation:erictraut commentedon Aug 10, 2023
I think this issue may have been addressed at some point. I'm not able to repro it with the latest mypy.
ilevkivskyi commentedon Aug 12, 2023
The original example still fails with
--check-untyped-defs, but now adding an explicitAnytype fixes the issue.