Skip to content

dmypy suggest should not suggest for abstract methods? #18965

Open
@asottile-sentry

Description

@asottile-sentry

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions