@@ -88,7 +88,7 @@ def mutable_during_init(
88
88
>>> from libtmux._internal.frozen_dataclass_sealable import (
89
89
... frozen_dataclass_sealable, mutable_during_init
90
90
... )
91
- >>>
91
+ >>>
92
92
>>> @frozen_dataclass_sealable
93
93
... class Example:
94
94
... name: str
@@ -181,25 +181,25 @@ def is_sealable(cls_or_obj: t.Any) -> bool:
181
181
-------
182
182
bool
183
183
True if the class or object is sealable, False otherwise
184
-
184
+
185
185
Examples
186
186
--------
187
187
>>> from dataclasses import dataclass
188
188
>>> from libtmux._internal.frozen_dataclass_sealable import (
189
189
... frozen_dataclass_sealable, is_sealable
190
190
... )
191
-
191
+
192
192
>>> # Regular class is not sealable
193
193
>>> @dataclass
194
194
... class Regular:
195
195
... value: int
196
-
196
+
197
197
>>> is_sealable(Regular)
198
198
False
199
199
>>> regular = Regular(value=42)
200
200
>>> is_sealable(regular)
201
201
False
202
-
202
+
203
203
>>> # Non-class objects are not sealable
204
204
>>> is_sealable("string")
205
205
False
@@ -210,10 +210,10 @@ def is_sealable(cls_or_obj: t.Any) -> bool:
210
210
"""
211
211
# If it's a class, check if it has a seal method
212
212
if isinstance (cls_or_obj , type ):
213
- return hasattr (cls_or_obj , "seal" ) and callable (getattr ( cls_or_obj , " seal" ) )
214
-
213
+ return hasattr (cls_or_obj , "seal" ) and callable (cls_or_obj . seal )
214
+
215
215
# If it's an instance, check if it has a seal method
216
- return hasattr (cls_or_obj , "seal" ) and callable (getattr ( cls_or_obj , " seal" ) )
216
+ return hasattr (cls_or_obj , "seal" ) and callable (cls_or_obj . seal )
217
217
218
218
219
219
@dataclass_transform (frozen_default = True )
@@ -223,7 +223,7 @@ def frozen_dataclass_sealable(
223
223
"""Create a dataclass that is immutable, with field-level mutability control.
224
224
225
225
Enhances the standard dataclass with:
226
-
226
+
227
227
- Core immutability (like dataclasses.frozen=True)
228
228
- Field-level mutability control during initialization
229
229
- Explicit sealing mechanism
@@ -250,7 +250,7 @@ def frozen_dataclass_sealable(
250
250
>>> from libtmux._internal.frozen_dataclass_sealable import (
251
251
... frozen_dataclass_sealable, is_sealable
252
252
... )
253
- >>>
253
+ >>>
254
254
>>> @frozen_dataclass_sealable
255
255
... class Config:
256
256
... name: str
@@ -575,6 +575,7 @@ def seal(self: t.Any, deep: bool = False) -> None:
575
575
field_value = getattr (self , field_obj .name , None )
576
576
# Check if the field value is sealable
577
577
from libtmux ._internal .frozen_dataclass_sealable import is_sealable
578
+
578
579
if field_value is not None and is_sealable (field_value ):
579
580
# Seal the nested object
580
581
field_value .seal (deep = True )
@@ -584,7 +585,7 @@ def seal(self: t.Any, deep: bool = False) -> None:
584
585
cls .__delattr__ = custom_delattr # type: ignore
585
586
cls .__init__ = custom_init # type: ignore
586
587
cls .seal = seal # type: ignore
587
-
588
+
588
589
# Add a class method to check if the class is sealable
589
590
@classmethod
590
591
def is_sealable (cls ) -> bool :
@@ -596,7 +597,7 @@ def is_sealable(cls) -> bool:
596
597
Always returns True for classes decorated with frozen_dataclass_sealable
597
598
"""
598
599
return True
599
-
600
+
600
601
cls .is_sealable = is_sealable # type: ignore
601
602
602
603
return cls
0 commit comments