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

1""" 

2Type-annotation related support for the referencing library. 

3""" 

4from __future__ import annotations 

5 

6from typing import TYPE_CHECKING, Protocol, TypeVar 

7 

8try: 

9 from collections.abc import Mapping as Mapping 

10 

11 Mapping[str, str] 

12except TypeError: # pragma: no cover 

13 from typing import Mapping as Mapping 

14 

15 

16if TYPE_CHECKING: 

17 from referencing._core import Resolved, Resolver, Resource 

18 

19#: A URI which identifies a `Resource`. 

20URI = str 

21 

22#: The type of documents within a registry. 

23D = TypeVar("D") 

24 

25 

26class Retrieve(Protocol[D]): 

27 """ 

28 A retrieval callable, usable within a `Registry` for resource retrieval. 

29 

30 Does not make assumptions about where the resource might be coming from. 

31 """ 

32 

33 def __call__(self, uri: URI) -> Resource[D]: 

34 """ 

35 Retrieve the resource with the given URI. 

36 

37 Raise `referencing.exceptions.NoSuchResource` if you wish to indicate 

38 the retriever cannot lookup the given URI. 

39 """ 

40 ... 

41 

42 

43class Anchor(Protocol[D]): 

44 """ 

45 An anchor within a `Resource`. 

46 

47 Beyond "simple" anchors, some specifications like JSON Schema's 2020 

48 version have dynamic anchors. 

49 """ 

50 

51 @property 

52 def name(self) -> str: 

53 """ 

54 Return the name of this anchor. 

55 """ 

56 ... 

57 

58 def resolve(self, resolver: Resolver[D]) -> Resolved[D]: 

59 """ 

60 Return the resource for this anchor. 

61 """ 

62 ...