Skip to content

Commit 0f07908

Browse files
committed
Pass the last remaining 2019 recursive ref test.
Something still seems slightly suspicious here, so it may pass all the tests but still be wrong :/ -- but it seems at least more correct that entering subresources (something done by implementations as they 'manually' process subschemas) should not affect dynamic_scope(), so that piece seems correcter. Whether we have precisely the right logic on when to append to the dynamic scope... we shall see. I think this may have a bit to do with picking a better value for "unidentified" root schemas (those without $id) than we currently have (where we use "").
1 parent beb23cf commit 0f07908

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

referencing/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def in_subresource(self, subresource: Resource[D]) -> Resolver[D]:
478478
id = subresource.id()
479479
if id is None:
480480
return self
481-
return self._evolve(base_uri=urljoin(self._base_uri, id))
481+
return evolve(self, base_uri=urljoin(self._base_uri, id))
482482

483483
def dynamic_scope(self) -> Iterable[tuple[URI, Registry[D]]]:
484484
"""
@@ -492,7 +492,7 @@ def _evolve(self, base_uri: str, **kwargs: Any):
492492
Evolve, appending to the dynamic scope.
493493
"""
494494
previous = self._previous
495-
if self._base_uri and base_uri != self._base_uri:
495+
if self._base_uri and (not previous or base_uri != self._base_uri):
496496
previous = previous.cons(self._base_uri)
497497
return evolve(self, base_uri=base_uri, previous=previous, **kwargs)
498498

referencing/tests/test_core.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def test_in_pointer_subresource(self):
739739
assert third.contents == {"ID": "grandchild"}
740740

741741
def test_dynamic_scope(self):
742-
root = ID_AND_CHILDREN.create_resource(
742+
one = ID_AND_CHILDREN.create_resource(
743743
{
744744
"ID": "http://example.com/",
745745
"children": [
@@ -750,19 +750,29 @@ def test_dynamic_scope(self):
750750
],
751751
},
752752
)
753-
registry = Registry().with_resource(root.id(), root)
753+
two = ID_AND_CHILDREN.create_resource(
754+
{
755+
"ID": "http://example.com/two",
756+
"children": [{"ID": "two-child/"}],
757+
},
758+
)
759+
registry = Registry().with_resources(
760+
[(one.id(), one), (two.id(), two)],
761+
)
754762

755763
resolver = registry.resolver()
756764
first = resolver.lookup("http://example.com/")
757765
second = first.resolver.lookup("#/children/0")
758766
third = second.resolver.lookup("grandchild")
767+
fourth = third.resolver.lookup("http://example.com/two")
768+
assert list(fourth.resolver.dynamic_scope()) == [
769+
("http://example.com/child/grandchild", fourth.resolver._registry),
770+
("http://example.com/child/", fourth.resolver._registry),
771+
]
759772
assert list(third.resolver.dynamic_scope()) == [
760773
("http://example.com/child/", third.resolver._registry),
761-
("http://example.com/", third.resolver._registry),
762-
]
763-
assert list(second.resolver.dynamic_scope()) == [
764-
("http://example.com/", second.resolver._registry),
765774
]
775+
assert list(second.resolver.dynamic_scope()) == []
766776
assert list(first.resolver.dynamic_scope()) == []
767777

768778

0 commit comments

Comments
 (0)