Skip to content

UP008 edge-case with slotted dataclasses #12506

@alexandermalyga

Description

@alexandermalyga

When using dataclasses with slots=True, calling a no-arg super() raises a TypeError, the workaround of using the two-arg variant triggers a UP008 rule error. Would be great if the rule took this edge-case into consideration.

From the docs:

Calling no-arg super() in dataclasses using slots=True will result in the following exception being raised: TypeError: super(type, obj): obj must be an instance or subtype of type. The two-arg super() is a valid workaround.

How to reproduce:

@dataclass(slots=True)
class Foo:
    bar: str

    def __post_init__(self) -> None:
        self.bar = "foo"


@dataclass(slots=True)
class Baz(Foo):
    def __post_init__(self) -> None:
        super(Baz, self).__post_init__()  # UP008 Use `super()` instead of `super(__class__, self)`
        self.bar = "baz"

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions