msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Subclasses of frozen Structs causing mypy error: `Cannot inherit non-frozen dataclass from a frozen one`

Open wikiped opened this issue 11 months ago • 2 comments

Description

With the following code:

import msgspec as ms


class Base(ms.Struct, frozen=True):
    ...


class Child(Base):
    ...


assert Child.__struct_config__.frozen is True

In a file: frozen.py

And the following command:

python -m mypy ./frozen.py

Outputs a false positive:

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

In a similar mypy issue the cause has been attributed to pydantic's use of dataclass_transform which might be having similar effects here.

This has been tested with:

mypy: 1.9.0 (compiled: yes)
msgspec: 0.18.6

wikiped avatar Mar 14 '24 15:03 wikiped