Skip to content

Commit 0c0f6cc

Browse files
committed
tests/examples/_internal/frozen_dataclass_sealable/test_basic.py(style): Update imports and formatting
why: Ensure consistency with project coding standards. what: - Added __future__ import for annotations - Reorganized imports with standard library first - Fixed whitespace and line breaks - Simplified type annotations using PEP 604 syntax (Union | None) - Improved code organization refs: Maintains code quality in example test files
1 parent b1850e7 commit 0c0f6cc

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Diff for: tests/examples/_internal/frozen_dataclass_sealable/test_basic.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
working code examples.
77
"""
88

9-
import pytest
9+
from __future__ import annotations
10+
11+
from dataclasses import field
1012

11-
from dataclasses import dataclass, field
12-
from typing import Optional
13+
import pytest
1314

1415
from libtmux._internal.frozen_dataclass_sealable import (
1516
frozen_dataclass_sealable,
@@ -19,72 +20,72 @@
1920

2021
def test_basic_usage():
2122
"""Test basic usage of frozen_dataclass_sealable."""
23+
2224
@frozen_dataclass_sealable
2325
class Config:
2426
name: str
2527

2628
values: dict[str, int] = field(
27-
default_factory=dict,
28-
metadata={"mutable_during_init": True}
29+
default_factory=dict, metadata={"mutable_during_init": True}
2930
)
3031

3132
# Create an instance
3233
config = Config(name="test-config")
3334
assert config.name == "test-config"
34-
35+
3536
# Cannot modify immutable fields
3637
with pytest.raises(AttributeError):
3738
config.name = "modified"
38-
39+
3940
# Can modify mutable fields
4041
config.values["key1"] = 100
4142
assert config.values["key1"] == 100
4243

4344
# Check sealable property
4445
assert is_sealable(config)
45-
46+
4647
# Seal the object
4748
config.seal()
4849
assert hasattr(config, "_sealed") and config._sealed
49-
50+
5051
# Can still modify contents of mutable containers after sealing
5152
config.values["key2"] = 200
5253
assert config.values["key2"] == 200
5354

5455

5556
def test_deferred_sealing():
5657
"""Test deferred sealing with linked nodes."""
58+
5759
@frozen_dataclass_sealable
5860
class Node:
5961
value: int
6062

61-
next_node: Optional['Node'] = field(
62-
default=None,
63-
metadata={"mutable_during_init": True}
63+
next_node: Node | None = field(
64+
default=None, metadata={"mutable_during_init": True}
6465
)
6566

6667
# Create a linked list (not circular to avoid recursion issues)
6768
node1 = Node(value=1)
6869
node2 = Node(value=2)
6970
node1.next_node = node2
70-
71+
7172
# Verify structure
7273
assert node1.value == 1
7374
assert node2.value == 2
7475
assert node1.next_node is node2
75-
76+
7677
# Verify sealable property
7778
assert is_sealable(node1)
7879
assert is_sealable(node2)
79-
80-
# Seal nodes individually
80+
81+
# Seal nodes individually
8182
node1.seal()
8283
node2.seal()
83-
84+
8485
# Verify both nodes are sealed
8586
assert hasattr(node1, "_sealed") and node1._sealed
8687
assert hasattr(node2, "_sealed") and node2._sealed
87-
88+
8889
# Verify immutability after sealing
8990
with pytest.raises(AttributeError):
9091
node1.value = 10

0 commit comments

Comments
 (0)