Skip to content
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

Do not require explicit override for plugin-generated methods #17370

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,14 @@ def check_explicit_override_decorator(
found_method_base_classes: list[TypeInfo] | None,
context: Context | None = None,
) -> None:
sym = defn.info.get(defn.name)
if (
found_method_base_classes
and not defn.is_explicit_override
and defn.name not in ("__init__", "__new__")
and not is_private(defn.name)
and sym is not None
and not sym.plugin_generated
):
self.msg.explicit_override_decorator_missing(
defn.name, found_method_base_classes[0].fullname, context or defn
Expand Down
15 changes: 14 additions & 1 deletion test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ class Foo:

[case testDataclassInheritanceWorksWithExplicitOverrides]
# flags: --enable-error-code explicit-override
from dataclasses import dataclass
from dataclasses import dataclass

@dataclass
class Base:
Expand All @@ -2475,3 +2475,16 @@ class Base:
class Child(Base):
y: int
[builtins fixtures/dataclasses.pyi]

[case testDataclassInheritanceWorksWithExplicitOverridesAndOrdering]
# flags: --enable-error-code explicit-override
from dataclasses import dataclass

@dataclass(order=True)
class Base:
x: int

@dataclass(order=True)
class Child(Base):
y: int
[builtins fixtures/dataclasses.pyi]
Loading