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

safe-super change breaks Mixin support #17192

Open
Kakadus opened this issue Apr 29, 2024 · 0 comments
Open

safe-super change breaks Mixin support #17192

Kakadus opened this issue Apr 29, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@Kakadus
Copy link

Kakadus commented Apr 29, 2024

Bug Report

We want to indicate that a (super-)class must implement a specific protocol in order to inherit from a specific (sub-) class. We used to annotate self as the super class in the subclass to express this. With mypy 1.10.0 this introduces a safe-super error. Is there currently a way to express this requirement?

To Reproduce

from typing import Protocol


class HasFormValid(Protocol):
    def form_valid(self, form):
        pass


class SaveValidFormMixin:

    def form_valid(self: HasFormValid, form):
        form.save()
        super().form_valid(form)

Expected Behavior

No error: Since we never actually inherit from the HasFormValid protocol, this should be safe.

Actual Behavior

mypy 1.10.0 treats HasFormValid.form_valid as trivial and warns about its usage. In this case, it is assured that HasFormValid.form_valid cannot be actually called via super().form_valid.

mypy <1.10.0 does not raise an error here.

Your Environment

  • Mypy version used: mypy 1.10.0 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12.3
@Kakadus Kakadus added the bug mypy got something wrong label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant