Coverage for src/annotated_doc/main.py: 100%
11 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-10-19 03:36 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-10-19 03:36 +0000
1class Doc: 1abnocpqdr
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.
6 The value should be a positional-only string literal to allow static tools
7 like editors and documentation generators to use it.
9 This complements docstrings.
11 The string value passed is available in the attribute `documentation`.
13 Example:
15 ```Python
16 from typing import Annotated
17 from annotated_doc import Doc
19 def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None:
20 print(f"Hi, {name}!")
21 ```
22 """
24 def __init__(self, documentation: str, /) -> None: 1abnocpqdr
25 self.documentation = documentation 1aKesLtMbNfuOvPQgwRxSThyUzVcWiAXBYZjC0D12kE3F4d5lG6H78mI9J!
27 def __repr__(self) -> str: 1abnocpqdr
28 return f"Doc({self.documentation!r})" 1eMfPgShViYj1k4l7m!
30 def __hash__(self) -> int: 1abnocpqdr
31 return hash(self.documentation) 1aKeLbNfOQgRThUcWiXZj02k3d5l68m9
33 def __eq__(self, other: object) -> bool: 1abnocpqdr
34 if not isinstance(other, Doc): 1aestbfuvgwxhyzciABjCDkEFdlGHmIJ
35 return NotImplemented 1efghijklm
36 return self.documentation == other.documentation 1aestbfuvgwxhyzciABjCDkEFdlGHmIJ