From 4d6730e3c4b4b2c7eb99fec023f0be1c4bb6e7eb Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 23 Oct 2025 15:48:31 -0700 Subject: [PATCH] Remove unused methods from Resource base class --- datasette/permissions.py | 31 ------------------------------- tests/test_actions_sql.py | 22 ---------------------- 2 files changed, 53 deletions(-) diff --git a/datasette/permissions.py b/datasette/permissions.py index df30c8ce..228bacd5 100644 --- a/datasette/permissions.py +++ b/datasette/permissions.py @@ -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).""" diff --git a/tests/test_actions_sql.py b/tests/test_actions_sql.py index d9cfd1ef..143faec9 100644 --- a/tests/test_actions_sql.py +++ b/tests/test_actions_sql.py @@ -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): """