Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/referencing/typing.py: 78%
18 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1"""
2Type-annotation related support for the referencing library.
3"""
4from __future__ import annotations
6from typing import TYPE_CHECKING, Protocol, TypeVar
8try:
9 from collections.abc import Mapping as Mapping
11 Mapping[str, str]
12except TypeError: # pragma: no cover
13 from typing import Mapping as Mapping
16if TYPE_CHECKING:
17 from referencing._core import Resolved, Resolver, Resource
19#: A URI which identifies a `Resource`.
20URI = str
22#: The type of documents within a registry.
23D = TypeVar("D")
26class Retrieve(Protocol[D]):
27 """
28 A retrieval callable, usable within a `Registry` for resource retrieval.
30 Does not make assumptions about where the resource might be coming from.
31 """
33 def __call__(self, uri: URI) -> Resource[D]:
34 """
35 Retrieve the resource with the given URI.
37 Raise `referencing.exceptions.NoSuchResource` if you wish to indicate
38 the retriever cannot lookup the given URI.
39 """
40 ...
43class Anchor(Protocol[D]):
44 """
45 An anchor within a `Resource`.
47 Beyond "simple" anchors, some specifications like JSON Schema's 2020
48 version have dynamic anchors.
49 """
51 @property
52 def name(self) -> str:
53 """
54 Return the name of this anchor.
55 """
56 ...
58 def resolve(self, resolver: Resolver[D]) -> Resolved[D]:
59 """
60 Return the resource for this anchor.
61 """
62 ...