You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[dataclass_transform] fix frozen behavior for base classes with direct metaclasses (#14878)
Fixes#14857. The initial implementation overlooked this statement in
[PEP 681](https://peps.python.org/pep-0681/#dataclass-semantics):
> Similarly, a class that directly specifies a metaclass that is
decorated with dataclass_transform is considered neither frozen nor
non-frozen.
As far as I can tell, this is a special case that _only_ applies to
classes that directly specify a `dataclass_transform` metaclass. This is
import for projects like Pydantic, which requires clients to use a base
class but still supports a `frozen` parameter.
Note that this allows mixed frozen and non-frozen behavior if the base
class _does_ have fields:
```
@dataclass_transform()
class Meta(type): ...
class Base(metaclass=Meta, frozen=False):
base: int = 0
class Foo(Base, frozen=True):
foo: int = 0
foo = Foo()
foo.foo = 1 # an error because Foo is frozen
foo.base = 1 # NOT an error — Base is neither frozen nor non-frozen
```
While this is probably surprising behavior, it seems to match the text
of the PEP as well as the behavior of Pyright.
0 commit comments