2Tests the typing.override decorator.
5# Specification: https://typing.readthedocs.io/en/latest/spec/class-compat.html#override
7from typing import Any, Callable, overload, override
10def wrapper(func: Callable[..., Any], /) -> Any:
11 def wrapped(*args: Any, **kwargs: Any) -> Any:
12 raise NotImplementedError
18 def method1(self) -> int:
22 def method2(self, x: int) -> int:
26 def method2(self, x: str) -> str:
29 def method2(self, x: int | str) -> int | str:
38 def method1(self) -> int: # OK
42 def method2(self, x: int) -> int:
46 def method2(self, x: str) -> str:
49 def method2(self, x: int | str) -> int | str: # OK
52 @override # E[method3]
53 def method3(self) -> int: # E[method3]: no matching signature in ancestor
Tag 'method3'
[invalid-explicit-override] Method `method3` is decorated with `@override` but does not override anything
56 @overload # E[method4]
57 def method4(self, x: int) -> int: # E[method4]
61 def method4(self, x: str) -> str:
64 @override # E[method4]
65 def method4(self, x: int | str) -> int | str: # E[method4]: no matching signature in ancestor
Tag 'method4'
[invalid-explicit-override] Method `method4` is decorated with `@override` but does not override anything
70 def method5(self): # OK
73 # > The @override decorator should be permitted anywhere a type checker
74 # > considers a method to be a valid override, which typically includes not
75 # > only normal methods but also @property, @staticmethod, and @classmethod.
78 @override # E[static_method1]
79 def static_method1() -> int: # E[static_method1]: no matching signature in ancestor
Tag 'static_method1'
[invalid-explicit-override] Method `static_method1` is decorated with `@override` but does not override anything
83 @override # E[class_method1]
84 def class_method1(cls) -> int: # E[class_method1]: no matching signature in ancestor
Tag 'class_method1'
[invalid-explicit-override] Method `class_method1` is decorated with `@override` but does not override anything
88 @override # E[property1]
89 def property1(self) -> int: # E[property1]: no matching signature in ancestor
Tag 'property1'
[invalid-explicit-override] Method `property1` is decorated with `@override` but does not override anything
93# Test the case where the parent derives from Any
101 def method1(self) -> None: # OK