ericvsmith / dataclasses

Apache License 2.0
584 stars 53 forks source link

TypeError when calling super() in dataclass(slots=True) subclass #171

Closed TomFryers closed 2 years ago

TomFryers commented 2 years ago

Basically, this issue with attrs also applies to dataclasses.

Trying to run this code

from dataclasses import dataclass

@dataclass(slots=True)
class Base:
    def hi(self):
        print("Hi")

@dataclass(slots=True)
class Sub(Base):
    def hi(self):
        super().hi()

Sub().hi()

gives this error message.

Traceback (most recent call last):
  File "...", line 16, in <module>
    Sub().hi()
  File "...", line 13, in hi
    super().hi()
TypeError: super(type, obj): obj must be an instance or subtype of type

Replacing super().hi() with super(Sub, self).hi() fixes this, but it's not ideal.

TomFryers commented 2 years ago

I think this is supposed to be on the main CPython issue tracker instead, and indeed it already exists there.

ericvsmith commented 2 years ago

Thanks, @TomFryers. You're correct, the main tracker is the place for this. I apologize for not responding to this issue when you created it, I'm behind on lots of things!