diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index 3b335429b98500..c3589db99a92be 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -3404,6 +3404,14 @@ class C: c = C('hello') self.assertEqual(deepcopy(c), c) + def test_frozen_slots_setattr(self): + # gh-143969: Ensure frozen+slots uses object.__setattr__ + @dataclass(frozen=True, slots=True) + class A: + x: int + a = A(1) + with self.assertRaisesRegex(FrozenInstanceError, 'cannot assign to field'): + a.x = 2 class TestSlots(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2026-01-17-23-15-55.gh-issue-143969.Waq8zN.rst b/Misc/NEWS.d/next/Library/2026-01-17-23-15-55.gh-issue-143969.Waq8zN.rst new file mode 100644 index 00000000000000..c0a0c71f21ca7c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-01-17-23-15-55.gh-issue-143969.Waq8zN.rst @@ -0,0 +1,2 @@ +Fixed a crash in frozen slotted dataclasses where assigning to an attribute +could raise an internal :exc:`TypeError` instead of failing cleanly.