Skip to content

dmypy suggest should not suggest for abstract methods? #18965

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

Open
asottile-sentry opened this issue Apr 24, 2025 · 1 comment
Open

dmypy suggest should not suggest for abstract methods? #18965

asottile-sentry opened this issue Apr 24, 2025 · 1 comment
Labels
bug mypy got something wrong topic-daemon dmypy

Comments

@asottile-sentry
Copy link

Bug Report

with --no-errors the suggestions from dmypy suggest for abstract methods can lead to type errors

To Reproduce

import abc

class C:
    @abc.abstractmethod
    def get_key(self): pass

class D(C):
    def get_key(self):
        return 'key'

Expected Behavior

either no suggestion or () -> str for t.C.get_key

Actual Behavior

$ dmypy run t.py
...
$ dmypy suggest t.D.get_key
() -> str
$ dmypy suggest t.C.get_key
() -> None

applying both of these suggestions results in a type error:

$ mypy t.py
t.py:8: error: Return type "str" of "get_key" incompatible with return type "None" in supertype "C"  [override]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.13.1
@sterliakov
Copy link
Collaborator

sterliakov commented Apr 26, 2025

dmypy suggest only considers calls and signatures in supertypes, so this logic doesn't consider subclasses and can't help annotate abstract methods. I agree that the easy sane solution is to skip suggesting @abstractmethod signature, or at least avoid suggesting -> None for abstract methods with empty body.

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-daemon dmypy
Projects
None yet
Development

No branches or pull requests

3 participants