Skip to content

Cannot inherit frozen dataclass from a non-frozen one error when using pydantic frozen=True #14857

@johnnyleitrim

Description

@johnnyleitrim

Bug Report

Specifying frozen=True as model class kwargs for pydantic models causes the following error to be emitted from mypy:

Cannot inherit frozen dataclass from a non-frozen one

To Reproduce

  1. Install pydantic and mypy: pip install pydantic mypy
  2. Create test.py with the following content:
from pydantic import BaseModel

class MyModel(BaseModel, frozen=True):
    my_val: int
  1. Run mypy on the test file: mypy test.py

Expected Behavior
No errors reported (as was the case with mypy 1.0.1):

> mypy test.py
Success: no issues found in 1 source file

Actual Behavior
Errors reported:

> mypy test.py
test.py:3: error: Cannot inherit frozen dataclass from a non-frozen one  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.1.1
  • Python version used: 3.10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions