@@ -3007,3 +3007,75 @@ class C(A):
30073007 def f(self, y: int | str) -> str: pass
30083008[typing fixtures/typing-full.pyi]
30093009[builtins fixtures/tuple.pyi]
3010+
3011+ [case requireExplicitOverrideMethod]
3012+ # flags: --strict-override-decorator --python-version 3.12
3013+ from typing import override
3014+
3015+ class A:
3016+ def f(self, x: int) -> str: pass
3017+
3018+ class B(A):
3019+ @override
3020+ def f(self, y: int) -> str: pass
3021+
3022+ class C(A):
3023+ def f(self, y: int) -> str: pass # E: Method "f" is not marked as override but is overriding a method in a base class
3024+ [typing fixtures/typing-override.pyi]
3025+
3026+ [case requireExplicitOverrideSpecialMethod]
3027+ # flags: --strict-override-decorator --python-version 3.12
3028+ from typing import Self, override
3029+
3030+ # Don't require override decorator for __init__ and __new__
3031+ # See: https://github.com/python/typing/issues/1376
3032+ class A:
3033+ def __init__(self) -> None: pass
3034+ def __new__(cls) -> Self: pass
3035+ [typing fixtures/typing-override.pyi]
3036+
3037+ [case requireExplicitOverrideProperty]
3038+ # flags: --strict-override-decorator --python-version 3.12
3039+ from typing import override
3040+
3041+ class A:
3042+ @property
3043+ def prop(self) -> int: pass
3044+
3045+ class B(A):
3046+ @override
3047+ @property
3048+ def prop(self) -> int: pass
3049+
3050+ class C(A):
3051+ @property
3052+ def prop(self) -> int: pass # E: Method "prop" is not marked as override but is overriding a method in a base class
3053+ [typing fixtures/typing-override.pyi]
3054+ [builtins fixtures/property.pyi]
3055+
3056+ [case requireExplicitOverrideOverload]
3057+ # flags: --strict-override-decorator --python-version 3.12
3058+ from typing import overload, override
3059+
3060+ class A:
3061+ @overload
3062+ def f(self, x: int) -> str: ...
3063+ @overload
3064+ def f(self, x: str) -> str: ...
3065+ def f(self, x): pass
3066+
3067+ class B(A):
3068+ @overload
3069+ def f(self, y: int) -> str: ...
3070+ @overload
3071+ def f(self, y: str) -> str: ...
3072+ @override
3073+ def f(self, y): pass
3074+
3075+ class C(A):
3076+ @overload
3077+ def f(self, y: int) -> str: ...
3078+ @overload
3079+ def f(self, y: str) -> str: ...
3080+ def f(self, y): pass # E: Method "f" is not marked as override but is overriding a method in a base class
3081+ [typing fixtures/typing-override.pyi]
0 commit comments