File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ def __eq__(self, other: object) -> bool:
124124 return NotImplemented
125125 return self .to_mode () == other .to_mode ()
126126
127+ def __hash__ (self ) -> int :
128+ return hash (self .to_mode ())
129+
127130
128131class FileMode (IntEnum ):
129132 ALL = 0o7
Original file line number Diff line number Diff line change 1+ from agents .sandbox .types import Group , Permissions , User
2+
3+
4+ def test_permissions_is_hashable () -> None :
5+ # ``Permissions`` overrides ``__eq__``; without a matching ``__hash__`` Pydantic v2
6+ # would set ``__hash__ = None``, breaking sets and dict keys for what is otherwise
7+ # a value-like type. Sibling classes ``User`` and ``Group`` already define both.
8+ perms = Permissions .from_mode (0o755 )
9+ other = Permissions .from_mode (0o755 )
10+ different = Permissions .from_mode (0o644 )
11+
12+ assert hash (perms ) == hash (other )
13+ assert hash (perms ) != hash (different )
14+ assert {perms , other , different } == {perms , different }
15+ assert {perms : "value" }[other ] == "value"
16+
17+
18+ def test_user_and_group_remain_hashable () -> None :
19+ # Regression guard for the sibling classes whose hashability the Permissions fix
20+ # mirrors.
21+ assert hash (User (name = "alice" )) == hash (User (name = "alice" ))
22+ assert hash (Group (name = "admin" , users = [])) == hash (Group (name = "admin" , users = []))
You can’t perform that action at this time.
0 commit comments