Skip to content

Commit 45d2c8e

Browse files
committed
!squash frozen_dataclass_selable
1 parent 6725952 commit 45d2c8e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/libtmux/_internal/frozen_dataclass_sealable.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def mutable_during_init(
8888
>>> from libtmux._internal.frozen_dataclass_sealable import (
8989
... frozen_dataclass_sealable, mutable_during_init
9090
... )
91-
>>>
91+
>>>
9292
>>> @frozen_dataclass_sealable
9393
... class Example:
9494
... name: str
@@ -181,25 +181,25 @@ def is_sealable(cls_or_obj: t.Any) -> bool:
181181
-------
182182
bool
183183
True if the class or object is sealable, False otherwise
184-
184+
185185
Examples
186186
--------
187187
>>> from dataclasses import dataclass
188188
>>> from libtmux._internal.frozen_dataclass_sealable import (
189189
... frozen_dataclass_sealable, is_sealable
190190
... )
191-
191+
192192
>>> # Regular class is not sealable
193193
>>> @dataclass
194194
... class Regular:
195195
... value: int
196-
196+
197197
>>> is_sealable(Regular)
198198
False
199199
>>> regular = Regular(value=42)
200200
>>> is_sealable(regular)
201201
False
202-
202+
203203
>>> # Non-class objects are not sealable
204204
>>> is_sealable("string")
205205
False
@@ -210,10 +210,10 @@ def is_sealable(cls_or_obj: t.Any) -> bool:
210210
"""
211211
# If it's a class, check if it has a seal method
212212
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+
215215
# 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)
217217

218218

219219
@dataclass_transform(frozen_default=True)
@@ -223,7 +223,7 @@ def frozen_dataclass_sealable(
223223
"""Create a dataclass that is immutable, with field-level mutability control.
224224
225225
Enhances the standard dataclass with:
226-
226+
227227
- Core immutability (like dataclasses.frozen=True)
228228
- Field-level mutability control during initialization
229229
- Explicit sealing mechanism
@@ -250,7 +250,7 @@ def frozen_dataclass_sealable(
250250
>>> from libtmux._internal.frozen_dataclass_sealable import (
251251
... frozen_dataclass_sealable, is_sealable
252252
... )
253-
>>>
253+
>>>
254254
>>> @frozen_dataclass_sealable
255255
... class Config:
256256
... name: str
@@ -575,6 +575,7 @@ def seal(self: t.Any, deep: bool = False) -> None:
575575
field_value = getattr(self, field_obj.name, None)
576576
# Check if the field value is sealable
577577
from libtmux._internal.frozen_dataclass_sealable import is_sealable
578+
578579
if field_value is not None and is_sealable(field_value):
579580
# Seal the nested object
580581
field_value.seal(deep=True)
@@ -584,7 +585,7 @@ def seal(self: t.Any, deep: bool = False) -> None:
584585
cls.__delattr__ = custom_delattr # type: ignore
585586
cls.__init__ = custom_init # type: ignore
586587
cls.seal = seal # type: ignore
587-
588+
588589
# Add a class method to check if the class is sealable
589590
@classmethod
590591
def is_sealable(cls) -> bool:
@@ -596,7 +597,7 @@ def is_sealable(cls) -> bool:
596597
Always returns True for classes decorated with frozen_dataclass_sealable
597598
"""
598599
return True
599-
600+
600601
cls.is_sealable = is_sealable # type: ignore
601602

602603
return cls

0 commit comments

Comments
 (0)