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

Dataclasses that inherit from other dataclasses fail type-checking when explicit-override is enabled #16452

Closed
adebrecht661 opened this issue Nov 10, 2023 · 4 comments · Fixed by #16464
Labels
bug mypy got something wrong topic-dataclasses

Comments

@adebrecht661
Copy link

adebrecht661 commented Nov 10, 2023

Bug Report

Dataclasses that inherit from other dataclasses fail type-checking when explicit-override is enabled. This appears to be due to an unannotated override being constructed for the new & improved replace typing.

To Reproduce

from dataclasses  import dataclass

@dataclass
class Base:
    ...

@dataclass
class Child(Base):
    ...

Actual Behavior

mypy errors on Child with

Method "__mypy-replace" is not using @override but is overriding a method in class "Base" [explicit-override]

Your Environment

  • Mypy version used: 1.7.0
  • Mypy configuration options from pyproject.toml:
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
warn_return_any = true
strict_equality = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
enable_error_code = "explicit-override"
namespace_packages = false
  • Python version used: 3.10.12
@adebrecht661 adebrecht661 added the bug mypy got something wrong label Nov 10, 2023
@AlexWaygood
Copy link
Member

cc. @ikonst

@yakMM
Copy link

yakMM commented Nov 11, 2023

Same problem here

@ikonst
Copy link
Contributor

ikonst commented Nov 11, 2023

Ah, gross! This is actually a private variable, maybe the right thing to do is to exempt it from @override logic?

@ilevkivskyi
Copy link
Member

maybe the right thing to do is to exempt it from @override logic?

Oh, it looks like I just did that in #16464 (and even more)

ilevkivskyi added a commit that referenced this issue Nov 12, 2023
Fixes #9910
Fixes #16452

We already exclude private names from override type compatibility checks
etc., but it looks like some override checks were still performed, we
need to skip them, since private name is actually a different name in
subclass.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
JukkaL pushed a commit that referenced this issue Nov 22, 2023
Fixes #9910
Fixes #16452

We already exclude private names from override type compatibility checks
etc., but it looks like some override checks were still performed, we
need to skip them, since private name is actually a different name in
subclass.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-dataclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants