Skip to content

Commit 67ce090

Browse files
committed
Ensure combining registries preserves the rest of the attributes.
1 parent 3f297f9 commit 67ce090

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

referencing/_core.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,19 @@ def combine(self, *registries: Registry[D]) -> Registry[D]:
304304
"""
305305
Combine together one or more other registries, producing a unified one.
306306
"""
307-
contents = (registry._resources for registry in registries)
308-
return evolve(self, resources=self._resources.update(*contents)) # type: ignore[reportUnknownMemberType] # noqa: E501
307+
anchors = self._anchors
308+
resources = self._resources
309+
uncrawled = self._uncrawled
310+
for registry in registries:
311+
anchors = anchors.update(registry._anchors) # type: ignore[reportUnknownMemberType] # noqa: E501
312+
resources = resources.update(registry._resources) # type: ignore[reportUnknownMemberType] # noqa: E501
313+
uncrawled = uncrawled.update(registry._uncrawled) # type: ignore[reportUnknownMemberType] # noqa: E501
314+
return evolve(
315+
self,
316+
anchors=anchors,
317+
resources=resources,
318+
uncrawled=uncrawled,
319+
)
309320

310321
def resolver(self, base_uri: URI = "") -> Resolver[D]:
311322
"""

referencing/tests/test_core.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pyrsistent import pmap
12
import pytest
23

34
from referencing import Anchor, Registry, Resource, Specification, exceptions
@@ -177,22 +178,39 @@ def test_combine(self):
177178
one = Resource.opaque(contents={})
178179
two = ID_AND_CHILDREN.create_resource({"foo": "bar"})
179180
three = ID_AND_CHILDREN.create_resource({"baz": "quux"})
181+
four = ID_AND_CHILDREN.create_resource({"anchors": {"foo": 12}})
180182

181183
first = Registry({"http://example.com/1": one})
182-
second = Registry({"http://example.com/foo/bar": two})
184+
second = Registry().with_resource("http://example.com/foo/bar", two)
183185
third = Registry(
184186
{
185187
"http://example.com/1": one,
186188
"http://example.com/baz": three,
187189
},
188190
)
189-
assert first.combine(second, third) == Registry(
191+
fourth = (
192+
Registry()
193+
.with_resource(
194+
"http://example.com/foo/quux",
195+
four,
196+
)
197+
.crawl()
198+
)
199+
assert first.combine(second, third, fourth) == Registry(
190200
[
191201
("http://example.com/1", one),
192-
("http://example.com/foo/bar", two),
193202
("http://example.com/baz", three),
203+
("http://example.com/foo/quux", four),
194204
],
195-
)
205+
anchors=pmap(
206+
{
207+
("http://example.com/foo/quux", "foo"): Anchor(
208+
name="foo",
209+
resource=ID_AND_CHILDREN.create_resource(12),
210+
),
211+
},
212+
),
213+
).with_resource("http://example.com/foo/bar", two)
196214

197215
def test_combine_with_uncrawled_resources(self):
198216
one = Resource.opaque(contents={})

0 commit comments

Comments
 (0)