Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/referencing/typing.py: 0%
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 typing import TYPE_CHECKING, Protocol, TypeVar
9try:
10 from collections.abc import Mapping as Mapping
12 Mapping[str, str]
13except TypeError: # pragma: no cover
14 from typing import Mapping as Mapping
17if TYPE_CHECKING:
18 from referencing._core import Resolved, Resolver, Resource
20#: A URI which identifies a `Resource`.
21URI = str
23#: The type of documents within a registry.
24D = TypeVar("D")
27class Retrieve(Protocol[D]):
28 """
29 A retrieval callable, usable within a `Registry` for resource retrieval.
31 Does not make assumptions about where the resource might be coming from.
32 """
34 def __call__(self, uri: URI) -> Resource[D]:
35 """
36 Retrieve the resource with the given URI.
38 Raise `referencing.exceptions.NoSuchResource` if you wish to indicate
39 the retriever cannot lookup the given URI.
40 """
41 ...
44class Anchor(Protocol[D]):
45 """
46 An anchor within a `Resource`.
48 Beyond "simple" anchors, some specifications like JSON Schema's 2020
49 version have dynamic anchors.
50 """
52 @property
53 def name(self) -> str:
54 """
55 Return the name of this anchor.
56 """
57 ...
59 def resolve(self, resolver: Resolver[D]) -> Resolved[D]:
60 """
61 Return the resource for this anchor.
62 """
63 ...