-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add support for PEP 698 - override decorator #14609
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 1 commit
8ea05d6
10cd4aa
94840af
f949dd4
192bc85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Also, mark the import from typing as Python 3.12 only. And change the message a bit.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2726,12 +2726,13 @@ g: Callable[[Union[Sequence[TI], Sequence[TS]]], None] | |
| f = g | ||
|
|
||
| [case explicitOverride] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| class A: | ||
| def f(self, x: int) -> str: pass | ||
| @override | ||
| def g(self, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(self, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class B(A): | ||
| @override | ||
|
|
@@ -2755,6 +2756,7 @@ class F(E): | |
| [builtins fixtures/tuple.pyi] | ||
|
|
||
| [case explicitOverrideStaticmethod] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| class A: | ||
|
|
@@ -2767,15 +2769,15 @@ class B(A): | |
| def f(x: int) -> str: pass | ||
| @override | ||
| @staticmethod | ||
| def g(x: int) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(x: int) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class C(A): # inverted order of decorators | ||
| @override | ||
| @staticmethod | ||
| def f(x: int) -> str: pass | ||
| @override | ||
| @staticmethod | ||
| def g(x: int) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(x: int) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class D(A): | ||
| @staticmethod | ||
|
|
@@ -2787,6 +2789,7 @@ class D(A): | |
| [builtins fixtures/callable.pyi] | ||
|
|
||
| [case explicitOverrideClassmethod] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| class A: | ||
|
|
@@ -2799,15 +2802,15 @@ class B(A): | |
| def f(cls, x: int) -> str: pass | ||
| @override | ||
| @classmethod | ||
| def g(cls, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(cls, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class C(A): # inverted order of decorators | ||
| @override | ||
| @classmethod | ||
| def f(cls, x: int) -> str: pass | ||
| @override | ||
| @classmethod | ||
| def g(cls, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(cls, x: int) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class D(A): | ||
| @classmethod | ||
|
|
@@ -2819,6 +2822,7 @@ class D(A): | |
| [builtins fixtures/callable.pyi] | ||
|
|
||
| [case explicitOverrideProperty] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| class A: | ||
|
|
@@ -2831,15 +2835,15 @@ class B(A): | |
| def f(self) -> str: pass | ||
| @override | ||
| @property | ||
| def g(self) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(self) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class C(A): # inverted order of decorators | ||
| @override | ||
| @property | ||
| def f(self) -> str: pass | ||
| @override | ||
| @property | ||
| def g(self) -> str: pass # E: Method "g" is marked as an override, but no base method with this name was found | ||
| def g(self) -> str: pass # E: Method "g" is marked as an override, but no base method was found with this name | ||
|
|
||
| class D(A): | ||
| @property | ||
|
|
@@ -2849,6 +2853,7 @@ class D(A): | |
| [typing fixtures/typing-full.pyi] | ||
|
|
||
| [case invalidExplicitOverride] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| @override # E: "override" used with a non-method | ||
|
|
@@ -2864,6 +2869,7 @@ def g() -> None: | |
| [builtins fixtures/tuple.pyi] | ||
|
|
||
| [case explicitOverrideSpecialMethods] | ||
| # flags: --python-version 3.12 | ||
| from typing import override | ||
|
|
||
| class A: | ||
|
|
@@ -2878,3 +2884,15 @@ class C: | |
| def __init__(self, a: int) -> None: pass | ||
| [typing fixtures/typing-full.pyi] | ||
| [builtins fixtures/tuple.pyi] | ||
|
|
||
| [case explicitOverrideFromExtensions] | ||
| from typing_extensions import override | ||
|
|
||
| class A: | ||
| def f(self, x: int) -> str: pass | ||
|
|
||
| class B(A): | ||
| @override | ||
| def f2(self, x: int) -> str: pass # E: Method "f2" is marked as an override, but no base method was found with this name | ||
| [typing fixtures/typing-full.pyi] | ||
| [builtins fixtures/tuple.pyi] | ||
|
Collaborator
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. I couldn't see a test case that uses overloaded methods (using the
Contributor
Author
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. I added the test and also added support for overloads decorated with |
||
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.
I wasn't sure whether to allow it on
__init__.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.
Doesn't seem very useful, but I also don't see a reason to explicitly disallow it. @stroxler any thoughts?