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

19 statements  

1""" 

2Type-annotation related support for the referencing library. 

3""" 

4 

5from __future__ import annotations 

6 

7from collections.abc import Mapping as Mapping 

8from typing import TYPE_CHECKING, Any, Protocol 

9 

10try: 

11 from typing_extensions import TypeVar 

12except ImportError: # pragma: no cover 

13 from typing import TypeVar 

14 

15if TYPE_CHECKING: 

16 from referencing._core import Resolved, Resolver, Resource 

17 

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

19URI = str 

20 

21#: The type of documents within a registry. 

22D = TypeVar("D", default=Any) 

23 

24 

25class Retrieve(Protocol[D]): 

26 """ 

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

28 

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

30 """ 

31 

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

33 """ 

34 Retrieve the resource with the given URI. 

35 

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

37 the retriever cannot lookup the given URI. 

38 """ 

39 ... 

40 

41 

42class Anchor(Protocol[D]): 

43 """ 

44 An anchor within a `Resource`. 

45 

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

47 version have dynamic anchors. 

48 """ 

49 

50 @property 

51 def name(self) -> str: 

52 """ 

53 Return the name of this anchor. 

54 """ 

55 ... 

56 

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

58 """ 

59 Return the resource for this anchor. 

60 """ 

61 ...