Skip to content

dataclasses that inherit from Protocol subclasses have wrong __init__ #883

@julianfortune

Description

@julianfortune

I believe bpo-44806: Fix __init__ in subclasses of protocols has caused a regression when using a Dataclass.

In Python 3.9.7, a dataclass that inherits from a subclass of typing.Protocol (i.e., a user-defined protocol), does not have the correct __init__.

Demonstration

from dataclasses import dataclass
from typing import Protocol

class P(Protocol):
    pass

@dataclass
class B(P):
    value: str

print(B("test"))

In 3.9.7:

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print(B("test"))
TypeError: B() takes no arguments

In 3.9.6:

B(value='test')

Affected Projects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions