Skip to content

Commit 281eae9

Browse files
committed
Stick anchors directly in the registry.
1 parent 11ca2b7 commit 281eae9

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

referencing/_core.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ class Anchor:
5252
resource: Schema
5353

5454
def added_to(self, registry: Registry):
55-
return registry.with_anchor(
56-
uri=self.uri,
57-
anchor=self.name,
58-
resource=self.resource,
59-
)
55+
return registry.with_anchor(anchor=self)
6056

6157

6258
@frozen
@@ -67,11 +63,7 @@ class DynamicAnchor:
6763
resource: Schema
6864

6965
def added_to(self, registry: Registry):
70-
return registry.with_anchor(
71-
uri=self.uri,
72-
anchor=self.name,
73-
resource=self.resource,
74-
)
66+
return registry.with_anchor(anchor=self)
7567

7668

7769
@frozen
@@ -126,10 +118,10 @@ def with_resources(self, pairs):
126118
contents = contents.set(id, (resource, m()))
127119
return attrs.evolve(self, contents=contents)
128120

129-
def with_anchor(self, uri, anchor, resource):
130-
uri_resource, anchors = self._contents[uri]
131-
new = uri_resource, anchors.set(anchor, resource)
132-
return attrs.evolve(self, contents=self._contents.set(uri, new))
121+
def with_anchor(self, anchor: Anchor | DynamicAnchor):
122+
uri_resource, anchors = self._contents[anchor.uri]
123+
new = uri_resource, anchors.set(anchor.name, anchor)
124+
return attrs.evolve(self, contents=self._contents.set(anchor.uri, new))
133125

134126
def resolver(self, root) -> Resolver:
135127
uri = id_of(root) or ""
@@ -168,7 +160,7 @@ def lookup(self, ref: str):
168160
segment = segment.replace("~1", "/").replace("~0", "~")
169161
target = target[segment]
170162
elif fragment:
171-
target = anchors[fragment]
163+
target = anchors[fragment].resource
172164

173165
return target, self.with_base_uri(uri)
174166

0 commit comments

Comments
 (0)