Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/referencing/typing.py: 79%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Type-annotation related support for the referencing library.
3"""
5from __future__ import annotations
7from collections.abc import Mapping as Mapping
8from typing import TYPE_CHECKING, Any, Protocol
10try:
11 from typing_extensions import TypeVar
12except ImportError: # pragma: no cover
13 from typing import TypeVar
15if TYPE_CHECKING:
16 from referencing._core import Resolved, Resolver, Resource
18#: A URI which identifies a `Resource`.
19URI = str
21#: The type of documents within a registry.
22D = TypeVar("D", default=Any)
25class Retrieve(Protocol[D]):
26 """
27 A retrieval callable, usable within a `Registry` for resource retrieval.
29 Does not make assumptions about where the resource might be coming from.
30 """
32 def __call__(self, uri: URI) -> Resource[D]:
33 """
34 Retrieve the resource with the given URI.
36 Raise `referencing.exceptions.NoSuchResource` if you wish to indicate
37 the retriever cannot lookup the given URI.
38 """
39 ...
42class Anchor(Protocol[D]):
43 """
44 An anchor within a `Resource`.
46 Beyond "simple" anchors, some specifications like JSON Schema's 2020
47 version have dynamic anchors.
48 """
50 @property
51 def name(self) -> str:
52 """
53 Return the name of this anchor.
54 """
55 ...
57 def resolve(self, resolver: Resolver[D]) -> Resolved[D]:
58 """
59 Return the resource for this anchor.
60 """
61 ...