-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not report plugin-generated methods with
explicit-override
(#17433)
Closes typeddjango/django-stubs#2226 Closes #17417 Closes #17370 Closes #17224 This is an alternative to #17418 Thanks a lot to @sterliakov, I took a dataclasses test case from #17370 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
18945af
commit 620e281
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Callable | ||
|
||
from mypy.plugin import ClassDefContext, Plugin | ||
from mypy.plugins.common import add_method | ||
from mypy.types import NoneType | ||
|
||
|
||
class AddOverrideMethodPlugin(Plugin): | ||
def get_class_decorator_hook_2(self, fullname: str) -> Callable[[ClassDefContext], bool] | None: | ||
if fullname == "__main__.inject_foo": | ||
return add_extra_methods_hook | ||
return None | ||
|
||
|
||
def add_extra_methods_hook(ctx: ClassDefContext) -> bool: | ||
add_method(ctx, "foo_implicit", [], NoneType()) | ||
return True | ||
|
||
|
||
def plugin(version: str) -> type[AddOverrideMethodPlugin]: | ||
return AddOverrideMethodPlugin |