Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dataclasses that inherit from Protocol subclasses have wrong __init__ #883

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

Closed
julianfortune opened this issue Sep 1, 2021 · 4 comments
Closed

Comments

@julianfortune
Copy link

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

@srittau
Copy link
Collaborator

srittau commented Sep 1, 2021

Please report this at bugs.python.org.

@srittau srittau closed this as completed Sep 1, 2021
@julianfortune
Copy link
Author

julianfortune commented Sep 1, 2021

Thanks for the fast response.

Python Issue

@AthenaCaesura
Copy link

This bug was solved in python 3.10, however the issue still remains for 3.9.7.

Is there any workaround that one could use instead of upgrading? Since 3.9.7 is the last version of 3.9 saying we don't support 3.9.7 is more or less the same as saying we don't support 3.9.

I would like to keep the frozen option if at all possible.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 17, 2022

Python 3.9.10 is the latest release of 3.9 and presumably contains python/cpython#28132

(this also isn't the right issue tracker for further discussion of this, please redirect to bugs.python.org)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants