MCPcopy Create free account
hub / github.com/dagger/dagger / get_doc

Function get_doc

sdk/python/src/dagger/mod/_utils.py:78–108  ·  view source on GitHub ↗

Get the last Doc() in an annotated type or the docstring of an object.

(obj: Any)

Source from the content-addressed store, hash-verified

76
77
78def get_doc(obj: Any) -> str | None:
79 """Get the last Doc() in an annotated type or the docstring of an object."""
80 if annotated := get_meta(obj, typing_extensions.Doc):
81 return annotated.documentation
82
83 # Avoid getting docs from builtins.
84 # We're only interested in things we decorate.
85 if inspect.getmodule(obj) == builtins or (
86 not inspect.isclass(obj) and not inspect.isroutine(obj)
87 ):
88 return None
89
90 # Don't look in base classes (otherwise just use inspect.get_doc).
91 try:
92 doc = obj.__doc__
93 except AttributeError:
94 return None
95 if not isinstance(doc, str):
96 return None
97
98 # By default, a dataclass's __doc__ will be the signature of the class,
99 # not None.
100 if (
101 doc
102 and dataclasses.is_dataclass(obj)
103 and doc.startswith(f"{obj.__name__}(")
104 and doc.endswith(")")
105 ):
106 return None
107
108 return inspect.cleandoc(doc)
109
110
111def get_ignore(obj: Any) -> list[str] | None:

Callers 7

_typedefsMethod · 0.90
docMethod · 0.90
_make_parameterMethod · 0.90
to_typedefFunction · 0.90
test_get_docFunction · 0.90
test_get_factory_docFunction · 0.90
test_no_annotated_docFunction · 0.90

Calls 1

get_metaFunction · 0.85

Tested by 3

test_get_docFunction · 0.72
test_get_factory_docFunction · 0.72
test_no_annotated_docFunction · 0.72