Remove unused methods from Resource base class

This commit is contained in:
Simon Willison 2025-10-23 15:48:31 -07:00
commit 4d6730e3c4
2 changed files with 0 additions and 53 deletions

View file

@ -37,37 +37,6 @@ class Resource(ABC):
"""
pass
def __str__(self) -> str:
if self.parent is None and self.child is None:
return f"{self.name}:*"
elif self.child is None:
return f"{self.name}:{self.parent}"
else:
return f"{self.name}:{self.parent}/{self.child}"
def __repr__(self) -> str:
parts = [f"{self.__class__.__name__}("]
args = []
if self.parent:
args.append(f"{self.parent!r}")
if self.child:
args.append(f"{self.child!r}")
parts.append(", ".join(args))
parts.append(")")
return "".join(parts)
def __eq__(self, other):
if not isinstance(other, Resource):
return False
return (
self.__class__ == other.__class__
and self.parent == other.parent
and self.child == other.child
)
def __hash__(self):
return hash((self.__class__, self.parent, self.child))
class AllowedResource(NamedTuple):
"""A resource with the reason it was allowed (for debugging)."""

View file

@ -264,28 +264,6 @@ async def test_child_allow_overrides_parent_deny(test_ds):
pm.unregister(plugin, name="test_plugin")
@pytest.mark.asyncio
async def test_resource_equality_and_hashing(test_ds):
"""Test that Resource instances support equality and hashing"""
# Create some resources
r1 = TableResource("analytics", "users")
r2 = TableResource("analytics", "users")
r3 = TableResource("analytics", "events")
# Test equality
assert r1 == r2
assert r1 != r3
# Test they can be used in sets
resource_set = {r1, r2, r3}
assert len(resource_set) == 2 # r1 and r2 are the same
# Test they can be used as dict keys
resource_dict = {r1: "data1", r3: "data2"}
assert resource_dict[r2] == "data1" # r2 same as r1
@pytest.mark.asyncio
async def test_sql_does_filtering_not_python(test_ds):
"""