Skip to content

Commit fb6886d

Browse files
committed
Minor tidying.
1 parent 9dac0d9 commit fb6886d

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

referencing/_core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from attrs import evolve, field
88
from pyrsistent import m, pmap
9-
from pyrsistent.typing import PMap
109

1110
from referencing._attrs import frozen
1211
from referencing.exceptions import CannotDetermineSpecification, Unresolvable
@@ -92,7 +91,7 @@ def opaque(cls, contents: D) -> Resource[D]:
9291
9392
See `Specification.OPAQUE` for details.
9493
"""
95-
return cls(contents=contents, specification=Specification.OPAQUE)
94+
return Specification.OPAQUE.create_resource(contents=contents)
9695

9796
def id(self) -> URI | None:
9897
"""
@@ -132,31 +131,31 @@ class Registry(Mapping[URI, Resource[D]]):
132131
registry with the additional resources added to them.
133132
"""
134133

135-
_contents: PMap[URI, Resource[D]] = field(default=m(), converter=pmap) # type: ignore[reportUnknownArgumentType] # noqa: E501
134+
_resources: Mapping[URI, Resource[D]] = field(default=m(), converter=pmap) # type: ignore[reportUnknownArgumentType] # noqa: E501
136135

137136
def __getitem__(self, uri: URI) -> Resource[D]:
138137
"""
139138
Return the `Resource` identified by the given URI.
140139
"""
141-
return self._contents[uri]
140+
return self._resources[uri]
142141

143142
def __iter__(self) -> Iterator[URI]:
144143
"""
145144
Iterate over all known URIs in the registry.
146145
"""
147-
return iter(self._contents)
146+
return iter(self._resources)
148147

149148
def __len__(self) -> int:
150149
"""
151150
Count the total number of (fully crawled) resources in this registry.
152151
"""
153-
return len(self._contents)
152+
return len(self._resources)
154153

155154
def contents(self, uri: URI) -> D:
156155
"""
157156
Retrieve the contents identified by the given URI.
158157
"""
159-
return self._contents[uri].contents
158+
return self._resources[uri].contents
160159

161160
def crawl(self) -> Registry[D]:
162161
"""
@@ -177,7 +176,7 @@ def with_resources(
177176
r"""
178177
Add the given `Resource`\ s to the registry, without crawling them.
179178
"""
180-
return evolve(self, contents=self._contents.update(pmap(pairs))) # type: ignore[reportUnknownArgumentType] # noqa: E501
179+
return evolve(self, resources=self._resources.update(pmap(pairs))) # type: ignore[reportUnknownArgumentType] # noqa: E501
181180

182181
def with_contents(
183182
self,
@@ -196,8 +195,8 @@ def combine(self, *registries: Registry[D]) -> Registry[D]:
196195
"""
197196
Combine together one or more other registries, producing a unified one.
198197
"""
199-
contents = (registry._contents for registry in registries)
200-
return evolve(self, contents=self._contents.update(*contents)) # type: ignore[reportUnknownMemberType] # noqa: E501
198+
contents = (registry._resources for registry in registries)
199+
return evolve(self, resources=self._resources.update(*contents)) # type: ignore[reportUnknownMemberType] # noqa: E501
201200

202201
def resolver(self, base_uri: URI = "") -> Resolver[D]:
203202
"""
@@ -229,7 +228,8 @@ class Resolver(Generic[D]):
229228
230229
The process of resolving a reference may itself involve calculating
231230
a *new* base URI for future reference resolution (e.g. if an
232-
intermediate resource sets a new base URI).
231+
intermediate resource sets a new base URI), or may involve encountering
232+
additional subresources and adding them to a new registry.
233233
"""
234234

235235
_base_uri: str = field(alias="base_uri")

referencing/jsonschema.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ def _legacy_id(contents: ObjectSchema) -> URI | None:
4646
DRAFT3 = Specification(id_of=_legacy_id)
4747

4848

49-
_SPECIFICATIONS: Registry[Specification[Schema]] = Registry().with_resources( # type: ignore[reportUnknownMemberType] # noqa: E501
50-
(dialect_id, Resource(contents=specification, specification=specification)) # type: ignore[reportUnknownArgumentType] # noqa: E501
51-
for dialect_id, specification in [
52-
("https://json-schema.org/draft/2020-12/schema", DRAFT202012),
53-
("https://json-schema.org/draft/2019-09/schema", DRAFT201909),
54-
("http://json-schema.org/draft-07/schema#", DRAFT7),
55-
("http://json-schema.org/draft-06/schema#", DRAFT6),
56-
("http://json-schema.org/draft-04/schema#", DRAFT4),
57-
("http://json-schema.org/draft-03/schema#", DRAFT3),
58-
]
49+
_SPECIFICATIONS: Registry[Specification[Schema]] = Registry(
50+
{
51+
dialect_id: Resource.opaque(specification)
52+
for dialect_id, specification in [
53+
("https://json-schema.org/draft/2020-12/schema", DRAFT202012),
54+
("https://json-schema.org/draft/2019-09/schema", DRAFT201909),
55+
("http://json-schema.org/draft-07/schema#", DRAFT7),
56+
("http://json-schema.org/draft-06/schema#", DRAFT6),
57+
("http://json-schema.org/draft-04/schema#", DRAFT4),
58+
("http://json-schema.org/draft-03/schema#", DRAFT3),
59+
]
60+
},
5961
)
6062

6163

referencing/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_iter(self):
7070
def test_crawl_still_has_top_level_resource(self):
7171
resource = Resource.opaque({"foo": "bar"})
7272
uri = "urn:example"
73-
registry = Registry().with_resources([(uri, resource)]).crawl()
73+
registry = Registry({uri: resource}).crawl()
7474
assert registry[uri] is resource
7575

7676
def test_contents(self):

0 commit comments

Comments
 (0)