Coverage for src/annotated_doc/main.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-12-05 11:36 +0000

1class Doc: 1abqrsctuvdwx

2 """Define the documentation of a type annotation using `Annotated`, to be 

3 used in class attributes, function and method parameters, return values, 

4 and variables. 

5 

6 The value should be a positional-only string literal to allow static tools 

7 like editors and documentation generators to use it. 

8 

9 This complements docstrings. 

10 

11 The string value passed is available in the attribute `documentation`. 

12 

13 Example: 

14 

15 ```Python 

16 from typing import Annotated 

17 from annotated_doc import Doc 

18 

19 def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None: 

20 print(f"Hi, {name}!") 

21 ``` 

22 """ 

23 

24 def __init__(self, documentation: str, /) -> None: 1abqrsctuvdwx

25 self.documentation = documentation 1aWeyXzYbZfA0B12gC3D45hE6F78iG9H!c#jI$J%'kK(L)*lM+N,-mO.P/d:nQ;R=?oS@T[]pU^V_

26 

27 def __repr__(self) -> str: 1abqrsctuvdwx

28 return f"Doc({self.documentation!r})" 1eYf1g4h7i!j%k)l,m/n=o[p_

29 

30 def __hash__(self) -> int: 1abqrsctuvdwx

31 return hash(self.documentation) 1aWeXbZf02g35h68i9c#j$'k(*l+-m.d:n;?o@]p^

32 

33 def __eq__(self, other: object) -> bool: 1abqrsctuvdwx

34 if not isinstance(other, Doc): 1aeyzbfABgCDhEFiGHcjIJkKLlMNmOPdnQRoSTpUV

35 return NotImplemented 1efghijklmnop

36 return self.documentation == other.documentation 1aeyzbfABgCDhEFiGHcjIJkKLlMNmOPdnQRoSTpUV