From 602e660eb486ceadb7492448a1570604785d9ad9 Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 10:50:39 +0300 Subject: [PATCH] Allow on_setattr=setters.NO_OP on frozen classes --- src/attr/_make.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/attr/_make.py b/src/attr/_make.py index 32e42976e..0f2ef48cc 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -2014,11 +2014,13 @@ def _make_init_script( attr_dict[a.name] = a if a.on_setattr is not None: - if frozen is True: + if a.on_setattr is setters.NO_OP: + pass + elif frozen is True: msg = "Frozen classes can't use on_setattr." raise ValueError(msg) - - needs_cached_setattr = True + else: + needs_cached_setattr = True elif has_cls_on_setattr and a.on_setattr is not setters.NO_OP: needs_cached_setattr = True