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

Problem inheriting from frozen native dataclass in some cases #4511

Closed
5 of 15 tasks
andriusbalcikonis opened this issue Sep 12, 2022 · 1 comment
Closed
5 of 15 tasks
Labels
bug V1 Bug related to Pydantic V1.X duplicate unconfirmed Bug not yet confirmed as valid/applicable

Comments

@andriusbalcikonis
Copy link

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

Getting TypeError: cannot inherit non-frozen dataclass from a frozen one when trying to dynamically create pydantic dataclass from native dataclass, which is marked as frozen.

Note: Issue does not happen in any situation - for example, if class B did not have method abc, problem does not happen.

Related to: #2557

Example Code

from dataclasses import dataclass

from pydantic.dataclasses import dataclass as pydantic_dataclass


@dataclass(frozen=True)
class A:
    field: int

@dataclass(frozen=True)
class B(A):
    field2: int

    def abc(self) -> None:
        pass

item = B(field=1, field2=2)

pydantic_dataclass(type(item))

Python, Pydantic & OS Version

pydantic version: 1.10.2
pydantic compiled: True
install path: /Users/(...)/.env/lib/python3.10/site-packages/pydantic
python version: 3.10.5 (v3.10.5:f377153967, Jun  6 2022, 12:36:10) [Clang 13.0.0 (clang-1300.0.29.30)]
platform: macOS-12.5-arm64-arm-64bit
optional deps. installed: ['typing-extensions']

Affected Components

@andriusbalcikonis andriusbalcikonis added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Sep 12, 2022
@hramezani
Copy link
Member

I think this is a duplicate of #4498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X duplicate unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

No branches or pull requests

3 participants