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

Bug: super() call in @dataclass(slots=True) causes TypeError #810

Closed
Gumminess opened this issue Mar 23, 2023 · 3 comments
Closed

Bug: super() call in @dataclass(slots=True) causes TypeError #810

Gumminess opened this issue Mar 23, 2023 · 3 comments

Comments

@Gumminess
Copy link

Gumminess commented Mar 23, 2023

When running this example you will get TypeError: super(type, obj): obj must be an instance or subtype of type

from dataclasses import dataclass
@dataclass(slots=True)
class Base:
    def method(self):
        print("hello")

@dataclass(slots=True)
class Derived(Base):
    def method(self):
        super().method()
        print("world")

Derived().method()

The solution is to call super(Derived, self) instead of super(), as explained here

The problem is that pyupgrade simplifies this to just plain super(), which is ok in most cases, but not here. As this is a standard behavior of a standard library, there should be a special case for this in pyupgrade.

@Gumminess Gumminess changed the title Bug: super() call in @dataclass(slots=True) causes Bug: super() call in @dataclass(slots=True) causes TypeError Mar 24, 2023
@asottile
Copy link
Owner

there's a few duplicates. this isn't a pyupgrade problem but a problem with dataclasses

h4l added a commit to h4l/v8serialize that referenced this issue Sep 14, 2024
Except for super() simplifications, which break dataclasses:
  asottile/pyupgrade#810
@bhperry
Copy link

bhperry commented Sep 30, 2024

This is a pyupgrade problem. Dataclass with slots creates a new class, because it's required for slots to work. Pyupgrade breaks the required format for datalass super with slots.

@asottile
Copy link
Owner

bet. python/cpython#90562

Repository owner locked as off-topic and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants