Skip to content

Commit 848f3aa

Browse files
committed
Slight improvements to a few more docstrings.
Particularly around making it clearer which functions only operate on crawled resources.
1 parent 5755a8f commit 848f3aa

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

referencing/_core.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class Registry(Mapping[URI, Resource[D]]):
238238

239239
def __getitem__(self, uri: URI) -> Resource[D]:
240240
"""
241-
Return the `Resource` identified by the given URI.
241+
Return the (already crawled) `Resource` identified by the given URI.
242242
"""
243243
try:
244244
return self._resources[uri]
@@ -247,7 +247,7 @@ def __getitem__(self, uri: URI) -> Resource[D]:
247247

248248
def __iter__(self) -> Iterator[URI]:
249249
"""
250-
Iterate over all fully crawled URIs in the registry.
250+
Iterate over all crawled URIs in the registry.
251251
"""
252252
return iter(self._resources)
253253

@@ -259,12 +259,12 @@ def __len__(self) -> int:
259259

260260
def __rmatmul__(self, new: Resource[D] | Iterable[Resource[D]]):
261261
"""
262-
Add resource(s) to a new registry, using their internal IDs.
262+
Create a new registry with resource(s) added using their internal IDs.
263263
264-
Resources must have a internal IDs (e.g. the ``$id`` keyword in modern
265-
JSON Schema versions), otherwise an error will be raised.
264+
Resources must have a internal IDs (e.g. the :kw:`$id` keyword in
265+
modern JSON Schema versions), otherwise an error will be raised.
266266
267-
Use this via:
267+
Both a single resource as well as an iterable of resources works, i.e.:
268268
269269
* ``resource @ registry`` or
270270
@@ -278,6 +278,12 @@ def __rmatmul__(self, new: Resource[D] | Iterable[Resource[D]]):
278278
registry.with_resources(
279279
(resource.id(), resource) for resource in new_resources
280280
)
281+
282+
Raises:
283+
284+
`NoInternalID`
285+
286+
if the resource(s) in fact do not have IDs
281287
"""
282288
if isinstance(new, Resource):
283289
new = (new,)
@@ -305,9 +311,13 @@ def __repr__(self) -> str:
305311
summary = f"{pluralized}"
306312
return f"<Registry ({size} {summary})>"
307313

308-
def get_or_retrieve(self, uri: URI):
314+
def get_or_retrieve(self, uri: URI) -> Retrieved:
309315
"""
310316
Get a resource from the registry, crawling or retrieving if necessary.
317+
318+
May involve crawling to find the given URI if it is not already known,
319+
so the returned object is a `Retrieved` object which contains both the
320+
resource value as well as the registry which ultimately contained it.
311321
"""
312322
resource = self._resources.get(uri)
313323
if resource is not None:
@@ -375,15 +385,15 @@ def anchor(self, uri: URI, name: str):
375385

376386
def contents(self, uri: URI) -> D:
377387
"""
378-
Retrieve the contents identified by the given URI.
388+
Retrieve the (already crawled) contents identified by the given URI.
379389
"""
380390
# Empty fragment URIs are equivalent to URIs without the fragment.
381391
# TODO: Is this true for non JSON Schema resources? Probably not.
382392
return self._resources[uri.rstrip("#")].contents
383393

384394
def crawl(self) -> Registry[D]:
385395
"""
386-
Immediately crawl all added resources, discovering subresources.
396+
Crawl all added resources, discovering subresources.
387397
"""
388398
resources = self._resources
389399
anchors = self._anchors

0 commit comments

Comments
 (0)