-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add strict_override_decorator
option (PEP 698)
#15512
Conversation
8ec9cb4
to
0827dcd
Compare
This comment has been minimized.
This comment has been minimized.
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.
One minor wording suggestion but I think this looks good otherwise!
0827dcd
to
de4590e
Compare
This comment has been minimized.
This comment has been minimized.
de4590e
to
6e40627
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Pushed a new update. The error message now includes the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Thanks for the PR! Looks good overall, some suggestions below. This is an important feature to have in mypy.
|
||
[case requireExplicitOverrideMultipleInheritance] | ||
# flags: --strict-override-decorator --python-version 3.12 | ||
from typing import override |
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.
Test using override
imported from typing_extensions
on an older Python version?
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 rather not do that. Since none of our test fixtures use @override
, we inadvertently get errors for those as well. That's also why I added a separate fixture for these test cases with just enough definitions and no accidental overrides. I would have to do the same just for the typing_extensions
fixture.
There is also a test case for an unused @override
already. As this PR doesn't change the decorator parsing, it probably fine to skip it.
mypy/test-data/unit/check-functions.test
Lines 2937 to 2947 in 67cc059
[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] |
Thanks for the review @JukkaL! Using a new error code instead of a cmd line option does make sense. The change was fairly strait forward. With that I also updated the documentation and added a whole new section in For now I used |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Thanks for the updates, looks good!
Add the strict mode for PEP 698.
Closes: #14072