| [case updateDataclassTransformParameterViaDecorator] | |
| # flags: --python-version 3.11 | |
| from m import my_dataclass | |
| @my_dataclass | |
| class Foo: | |
| x: int | |
| foo = Foo(1) | |
| foo.x = 2 | |
| [file m.py] | |
| from typing import dataclass_transform | |
| @dataclass_transform(frozen_default=False) | |
| def my_dataclass(cls): return cls | |
| [file m.py.2] | |
| from typing import dataclass_transform | |
| @dataclass_transform(frozen_default=True) | |
| def my_dataclass(cls): return cls | |
| [typing fixtures/typing-full.pyi] | |
| [builtins fixtures/dataclasses.pyi] | |
| [out] | |
| == | |
| main:9: error: Property "x" defined in "Foo" is read-only | |
| [case updateDataclassTransformParameterViaParentClass] | |
| # flags: --python-version 3.11 | |
| from m import Dataclass | |
| class Foo(Dataclass): | |
| x: int | |
| foo = Foo(1) | |
| foo.x = 2 | |
| [file m.py] | |
| from typing import dataclass_transform | |
| @dataclass_transform(frozen_default=False) | |
| class Dataclass: ... | |
| [file m.py.2] | |
| from typing import dataclass_transform | |
| @dataclass_transform(frozen_default=True) | |
| class Dataclass: ... | |
| [typing fixtures/typing-full.pyi] | |
| [builtins fixtures/dataclasses.pyi] | |
| [out] | |
| == | |
| main:8: error: Property "x" defined in "Foo" is read-only | |
| [case updateBaseClassToUseDataclassTransform] | |
| # flags: --python-version 3.11 | |
| from m import A | |
| class B(A): | |
| y: int | |
| B(x=1, y=2) | |
| [file m.py] | |
| class Dataclass: ... | |
| class A(Dataclass): | |
| x: int | |
| [file m.py.2] | |
| from typing import dataclass_transform | |
| @dataclass_transform() | |
| class Dataclass: ... | |
| class A(Dataclass): | |
| x: int | |
| [typing fixtures/typing-full.pyi] | |
| [builtins fixtures/dataclasses.pyi] | |
| [out] | |
| main:7: error: Unexpected keyword argument "x" for "B" | |
| main:7: error: Unexpected keyword argument "y" for "B" | |
| == | |
| [case frozenInheritanceViaDefault] | |
| # flags: --python-version 3.11 | |
| from foo import Foo | |
| foo = Foo(base=0, foo=1) | |
| [file transform.py] | |
| from typing import dataclass_transform, Type | |
| @dataclass_transform(frozen_default=True) | |
| def dataclass(cls: Type) -> Type: return cls | |
| [file base.py] | |
| from transform import dataclass | |
| @dataclass | |
| class Base: | |
| base: int | |
| [file foo.py] | |
| from base import Base | |
| from transform import dataclass | |
| @dataclass | |
| class Foo(Base): | |
| foo: int | |
| [file foo.py.2] | |
| from base import Base | |
| from transform import dataclass | |
| @dataclass | |
| class Foo(Base): | |
| foo: int | |
| bar: int = 0 | |
| [typing fixtures/typing-full.pyi] | |
| [builtins fixtures/dataclasses.pyi] | |
| # If the frozen parameter is being maintained correctly, we *don't* expect to see issues; if it's | |
| # broken in incremental mode, then we'll see an error about inheriting a non-frozen class from a | |
| # frozen one. | |
| # | |
| # Ideally we'd also add a `foo.foo = 2` to confirm that frozen semantics are actually being | |
| # enforced, but incremental tests currently can't start with an error, which makes it tricky to | |
| # write such a test case. | |
| [out] | |
| == |