Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
)
TARGET_CLASS_HAS_NO_BASE_CLASS: Final = ErrorMessage("Target class has no base class")
SUPER_OUTSIDE_OF_METHOD_NOT_SUPPORTED: Final = ErrorMessage(
"super() outside of a method is not supported"
'"super()" outside of a method is not supported'
)
SUPER_ENCLOSING_POSITIONAL_ARGS_REQUIRED: Final = ErrorMessage(
"super() requires one or more positional arguments in enclosing function"
'"super()" requires one or two positional arguments in enclosing function'
)

# Self-type
Expand Down
21 changes: 17 additions & 4 deletions test-data/unit/check-super.test
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ class B(A):


[case testSuperOutsideMethodNoCrash]
class C:
a = super().whatever # E: super() outside of a method is not supported
class A:
x = 1
class B(A): pass
class C(B):
b = super(B, B).x
a = super().whatever # E: "super()" outside of a method is not supported

[case testSuperWithObjectClassAsFirstArgument]
class A:
Expand Down Expand Up @@ -366,13 +370,22 @@ class C(B):
[case testSuperInMethodWithNoArguments]
class A:
def f(self) -> None: pass
@staticmethod
def st() -> int:
return 1

class B(A):
def g() -> None: # E: Method must have at least one argument. Did you forget the "self" argument?
super().f() # E: super() requires one or more positional arguments in enclosing function
super().f() # E: "super()" requires one or two positional arguments in enclosing function
def h(self) -> None:
def a() -> None:
super().f() # E: super() requires one or more positional arguments in enclosing function
super().f() # E: "super()" requires one or two positional arguments in enclosing function
@staticmethod
def st() -> int:
reveal_type(super(B, B).st()) # N: Revealed type is "builtins.int"
super().st() # E: "super()" requires one or two positional arguments in enclosing function
return 2
[builtins fixtures/staticmethod.pyi]

[case testSuperWithUnsupportedTypeObject]
from typing import Type
Expand Down