|
41 | 41 | from typing import TypeAlias |
42 | 42 | from typing import TypedDict |
43 | 43 | from typing import TypeVar |
| 44 | +from typing import cast |
44 | 45 | from typing import get_origin |
45 | 46 | from typing import is_typeddict |
46 | 47 | import warnings |
47 | 48 |
|
| 49 | +from pdoc import _pydantic |
48 | 50 | from pdoc import doc_ast |
49 | 51 | from pdoc import doc_pyi |
50 | 52 | from pdoc import extract |
@@ -209,7 +211,10 @@ def __lt__(self, other): |
209 | 211 | ) |
210 | 212 |
|
211 | 213 |
|
212 | | -class Namespace(Doc[T], metaclass=ABCMeta): |
| 214 | +U = TypeVar("U", bound=types.ModuleType | type) |
| 215 | + |
| 216 | + |
| 217 | +class Namespace(Doc[U], metaclass=ABCMeta): |
213 | 218 | """ |
214 | 219 | A documentation object that can have children. In other words, either a module or a class. |
215 | 220 | """ |
@@ -318,13 +323,17 @@ def members(self) -> dict[str, Doc]: |
318 | 323 | qualname, |
319 | 324 | docstring="", |
320 | 325 | annotation=self._var_annotations.get(name, empty), |
321 | | - default_value=obj, |
| 326 | + default_value=_pydantic.default_value(self.obj, name, obj), |
322 | 327 | taken_from=taken_from, |
323 | 328 | ) |
324 | | - if self._var_docstrings.get(name): |
| 329 | + |
| 330 | + if _doc := _pydantic.get_field_docstring(cast(type, self.obj), name): |
| 331 | + doc.docstring = _doc |
| 332 | + elif self._var_docstrings.get(name): |
325 | 333 | doc.docstring = self._var_docstrings[name] |
326 | | - if self._func_docstrings.get(name) and not doc.docstring: |
| 334 | + elif self._func_docstrings.get(name) and not doc.docstring: |
327 | 335 | doc.docstring = self._func_docstrings[name] |
| 336 | + |
328 | 337 | members[doc.name] = doc |
329 | 338 |
|
330 | 339 | if isinstance(self, Module): |
@@ -774,6 +783,12 @@ def _member_objects(self) -> dict[str, Any]: |
774 | 783 | for cls in self._bases: |
775 | 784 | sorted, unsorted = doc_ast.sort_by_source(cls, sorted, unsorted) |
776 | 785 | sorted.update(unsorted) |
| 786 | + |
| 787 | + if _pydantic.is_pydantic_model(self.obj): |
| 788 | + sorted = { |
| 789 | + k: v for k, v in sorted.items() if k not in _pydantic.IGNORED_FIELDS |
| 790 | + } |
| 791 | + |
777 | 792 | return sorted |
778 | 793 |
|
779 | 794 | @cached_property |
@@ -904,7 +919,7 @@ def __init__( |
904 | 919 | else: |
905 | 920 | unwrapped = func |
906 | 921 | super().__init__(modulename, qualname, unwrapped, taken_from) |
907 | | - self.wrapped = func |
| 922 | + self.wrapped = func # type: ignore |
908 | 923 |
|
909 | 924 | @cache |
910 | 925 | @_include_fullname_in_traceback |
|
0 commit comments