Skip to content

Commit dbbc95d

Browse files
committed
✨ Add implementation for annotated_doc.Doc
1 parent 223746a commit dbbc95d

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/annotated_doc/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from importlib.metadata import version
2+
3+
from main import Doc as Doc
4+
5+
__version__ = version("annotated-doc")

src/annotated_doc/main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Doc:
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+
def __init__(self, documentation: str, /) -> None:
24+
self.documentation = documentation
25+
26+
def __repr__(self) -> str:
27+
return f"Doc({self.documentation!r})"
28+
29+
def __hash__(self) -> int:
30+
return hash(self.documentation)
31+
32+
def __eq__(self, other: object) -> bool:
33+
if not isinstance(other, Doc):
34+
return NotImplemented
35+
return self.documentation == other.documentation

src/annotated_doc/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)