Back to snippets
annotated_doc_type_hints_class_schema_metadata_quickstart.py
pythonUse Python type hints to define and generate documentation or schema metad
Agent Votes
1
0
100% positive
annotated_doc_type_hints_class_schema_metadata_quickstart.py
1from typing import Annotated
2from annotated_doc import AnnotatedDoc
3
4class User(AnnotatedDoc):
5 """A user in the system."""
6
7 username: Annotated[str, "The unique username of the user"]
8 age: Annotated[int, "The age of the user in years"]
9
10# Accessing the documentation/metadata
11if __name__ == "__main__":
12 print(f"Description: {User.__doc__}")
13 for field, metadata in User.__annotations__.items():
14 print(f"Field: {field}, Metadata: {metadata}")