Skip to content

Commit 10c35b8

Browse files
committed
suppress BaseModel fields
1 parent adbe853 commit 10c35b8

File tree

3 files changed

+8
-167
lines changed

3 files changed

+8
-167
lines changed

pdoc/doc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,15 @@ def members(self) -> dict[str, Doc]:
256256
"""
257257
members: dict[str, Doc] = {}
258258
for name, obj in self._member_objects.items():
259-
if _pydantic._PYDANTIC_ENABLED and name in _pydantic._IGNORED_FIELDS:
260-
continue
261-
262259
qualname = f"{self.qualname}.{name}".lstrip(".")
263260
taken_from = self._taken_from(name, obj)
261+
262+
if _pydantic._PYDANTIC_ENABLED and (
263+
name in _pydantic._IGNORED_FIELDS
264+
or taken_from[0].startswith("pydantic")
265+
):
266+
continue
267+
264268
doc: Doc[Any]
265269

266270
is_classmethod = isinstance(obj, classmethod)

test/testdata/with_pydantic.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ <h1 class="modulename">
104104
<p>Attributes:
105105
__class_vars__: The names of the class variables defined on the model.
106106
__private_attributes__: Metadata about the private attributes of the model.
107-
__signature__: The synthesized <code><a href="#Foo.__init__">__init__</a></code> [<code>Signature</code>][inspect.Signature] of the model.</p>
107+
__signature__: The synthesized <code>__init__</code> [<code>Signature</code>][inspect.Signature] of the model.</p>
108108

109109
<pre><code>__pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
110110
__pydantic_core_schema__: The core schema of the model.

test/testdata/with_pydantic.txt

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,7 @@
11
<module with_pydantic # A small example with…
22
<class with_pydantic.Foo # !!! abstract "Usage …
3-
<method def __init__(self, /, **data: Any): ... # inherited from pydantic.main.BaseModel.__init__, Create a new model b…>
43
<var a: int = 1>
54
<var b: int = 2 # Docstring for b.>
65
<var model_config: ClassVar[pydantic.config.ConfigDict] = {} # Configuration for th…>
7-
<method def model_fields(unknown): ... # inherited from pydantic.main.BaseModel.model_fields, A decorator exposing…>
8-
<method def model_computed_fields(unknown): ... # inherited from pydantic.main.BaseModel.model_computed_fields, A decorator exposing…>
9-
<var model_extra: dict[str, typing.Any] | None # inherited from pydantic.main.BaseModel.model_extra, Get extra fields set…>
10-
<var model_fields_set: set[str] # inherited from pydantic.main.BaseModel.model_fields_set, Returns the set of f…>
11-
<@classmethod class def model_construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self: ... # inherited from pydantic.main.BaseModel.model_construct, Creates a new instan…>
12-
<method def model_copy(
13-
self,
14-
*,
15-
update: Mapping[str, typing.Any] | None = None,
16-
deep: bool = False
17-
) -> Self: ... # inherited from pydantic.main.BaseModel.model_copy, !!! abstract "Usage …>
18-
<method def model_dump(
19-
self,
20-
*,
21-
mode: Union[Literal['json', 'python'], str] = 'python',
22-
include: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
23-
exclude: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
24-
context: typing.Any | None = None,
25-
by_alias: bool | None = None,
26-
exclude_unset: bool = False,
27-
exclude_defaults: bool = False,
28-
exclude_none: bool = False,
29-
exclude_computed_fields: bool = False,
30-
round_trip: bool = False,
31-
warnings: Union[bool, Literal['none', 'warn', 'error']] = True,
32-
fallback: Optional[Callable[[Any], Any]] = None,
33-
serialize_as_any: bool = False
34-
) -> dict[str, typing.Any]: ... # inherited from pydantic.main.BaseModel.model_dump, !!! abstract "Usage …>
35-
<method def model_dump_json(
36-
self,
37-
*,
38-
indent: int | None = None,
39-
ensure_ascii: bool = False,
40-
include: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
41-
exclude: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
42-
context: typing.Any | None = None,
43-
by_alias: bool | None = None,
44-
exclude_unset: bool = False,
45-
exclude_defaults: bool = False,
46-
exclude_none: bool = False,
47-
exclude_computed_fields: bool = False,
48-
round_trip: bool = False,
49-
warnings: Union[bool, Literal['none', 'warn', 'error']] = True,
50-
fallback: Optional[Callable[[Any], Any]] = None,
51-
serialize_as_any: bool = False
52-
) -> str: ... # inherited from pydantic.main.BaseModel.model_dump_json, !!! abstract "Usage …>
53-
<@classmethod class def model_json_schema(
54-
cls,
55-
by_alias: bool = True,
56-
ref_template: str = '#/$defs/{model}',
57-
schema_generator: type[pydantic.json_schema.GenerateJsonSchema] = <class 'pydantic.json_schema.GenerateJsonSchema'>,
58-
mode: Literal['validation', 'serialization'] = 'validation',
59-
*,
60-
union_format: Literal['any_of', 'primitive_type_array'] = 'any_of'
61-
) -> dict[str, typing.Any]: ... # inherited from pydantic.main.BaseModel.model_json_schema, Generates a JSON sch…>
62-
<@classmethod class def model_parametrized_name(cls, params: tuple[type[typing.Any], ...]) -> str: ... # inherited from pydantic.main.BaseModel.model_parametrized_name, Compute the class na…>
63-
<method def model_post_init(self, context: Any, /) -> None: ... # inherited from pydantic.main.BaseModel.model_post_init, Override this method…>
64-
<@classmethod class def model_rebuild(
65-
cls,
66-
*,
67-
force: bool = False,
68-
raise_errors: bool = True,
69-
_parent_namespace_depth: int = 2,
70-
_types_namespace: Mapping[str, typing.Any] | None = None
71-
) -> bool | None: ... # inherited from pydantic.main.BaseModel.model_rebuild, Try to rebuild the p…>
72-
<@classmethod class def model_validate(
73-
cls,
74-
obj: Any,
75-
*,
76-
strict: bool | None = None,
77-
extra: Optional[Literal['allow', 'ignore', 'forbid']] = None,
78-
from_attributes: bool | None = None,
79-
context: typing.Any | None = None,
80-
by_alias: bool | None = None,
81-
by_name: bool | None = None
82-
) -> Self: ... # inherited from pydantic.main.BaseModel.model_validate, Validate a pydantic …>
83-
<@classmethod class def model_validate_json(
84-
cls,
85-
json_data: str | bytes | bytearray,
86-
*,
87-
strict: bool | None = None,
88-
extra: Optional[Literal['allow', 'ignore', 'forbid']] = None,
89-
context: typing.Any | None = None,
90-
by_alias: bool | None = None,
91-
by_name: bool | None = None
92-
) -> Self: ... # inherited from pydantic.main.BaseModel.model_validate_json, !!! abstract "Usage …>
93-
<@classmethod class def model_validate_strings(
94-
cls,
95-
obj: Any,
96-
*,
97-
strict: bool | None = None,
98-
extra: Optional[Literal['allow', 'ignore', 'forbid']] = None,
99-
context: typing.Any | None = None,
100-
by_alias: bool | None = None,
101-
by_name: bool | None = None
102-
) -> Self: ... # inherited from pydantic.main.BaseModel.model_validate_strings, Validate the given o…>
103-
<@typing_extensions.deprecated('The `dict` method is deprecated; use `model_dump` instead.', category=None) method def dict(
104-
self,
105-
*,
106-
include: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
107-
exclude: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
108-
by_alias: bool = False,
109-
exclude_unset: bool = False,
110-
exclude_defaults: bool = False,
111-
exclude_none: bool = False
112-
) -> Dict[str, Any]: ... # inherited from pydantic.main.BaseModel.dict>
113-
<@typing_extensions.deprecated('The `json` method is deprecated; use `model_dump_json` instead.', category=None) method def json(
114-
self,
115-
*,
116-
include: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
117-
exclude: Union[set[int], set[str], Mapping[int, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], Mapping[str, Union[set[int], set[str], Mapping[int, Union[ForwardRef('IncEx'), bool]], Mapping[str, Union[ForwardRef('IncEx'), bool]], bool]], NoneType] = None,
118-
by_alias: bool = False,
119-
exclude_unset: bool = False,
120-
exclude_defaults: bool = False,
121-
exclude_none: bool = False,
122-
encoder: Optional[Callable[[Any], Any]] = PydanticUndefined,
123-
models_as_dict: bool = PydanticUndefined,
124-
**dumps_kwargs: Any
125-
) -> str: ... # inherited from pydantic.main.BaseModel.json>
126-
<@classmethod @typing_extensions.deprecated('The `parse_obj` method is deprecated; use `model_validate` instead.', category=None) class def parse_obj(cls, obj: Any) -> Self: ... # inherited from pydantic.main.BaseModel.parse_obj>
127-
<@classmethod @typing_extensions.deprecated('The `parse_raw` method is deprecated; if your data is JSON use `model_validate_json`, otherwise load the data then use `model_validate` instead.', category=None) class def parse_raw(
128-
cls,
129-
b: str | bytes,
130-
*,
131-
content_type: str | None = None,
132-
encoding: str = 'utf8',
133-
proto: pydantic.deprecated.parse.Protocol | None = None,
134-
allow_pickle: bool = False
135-
) -> Self: ... # inherited from pydantic.main.BaseModel.parse_raw>
136-
<@classmethod @typing_extensions.deprecated('The `parse_file` method is deprecated; load the data from file, then if your data is JSON use `model_validate_json`, otherwise `model_validate` instead.', category=None) class def parse_file(
137-
cls,
138-
path: str | pathlib._local.Path,
139-
*,
140-
content_type: str | None = None,
141-
encoding: str = 'utf8',
142-
proto: pydantic.deprecated.parse.Protocol | None = None,
143-
allow_pickle: bool = False
144-
) -> Self: ... # inherited from pydantic.main.BaseModel.parse_file>
145-
<@classmethod @typing_extensions.deprecated("The `from_orm` method is deprecated; set `model_config['from_attributes']=True` and use `model_validate` instead.", category=None) class def from_orm(cls, obj: Any) -> Self: ... # inherited from pydantic.main.BaseModel.from_orm>
146-
<@classmethod @typing_extensions.deprecated('The `construct` method is deprecated; use `model_construct` instead.', category=None) class def construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self: ... # inherited from pydantic.main.BaseModel.construct>
147-
<@typing_extensions.deprecated('The `copy` method is deprecated; use `model_copy` instead. See the docstring of `BaseModel.copy` for details about how to handle `include` and `exclude`.', category=None) method def copy(
148-
self,
149-
*,
150-
include: Set[int] | Set[str] | Mapping[int, typing.Any] | Mapping[str, typing.Any] | None = None,
151-
exclude: Set[int] | Set[str] | Mapping[int, typing.Any] | Mapping[str, typing.Any] | None = None,
152-
update: Optional[Dict[str, Any]] = None,
153-
deep: bool = False
154-
) -> Self: ... # inherited from pydantic.main.BaseModel.copy, Returns a copy of th…>
155-
<@classmethod @typing_extensions.deprecated('The `schema` method is deprecated; use `model_json_schema` instead.', category=None) class def schema(
156-
cls,
157-
by_alias: bool = True,
158-
ref_template: str = '#/$defs/{model}'
159-
) -> Dict[str, Any]: ... # inherited from pydantic.main.BaseModel.schema>
160-
<@classmethod @typing_extensions.deprecated('The `schema_json` method is deprecated; use `model_json_schema` and json.dumps instead.', category=None) class def schema_json(
161-
cls,
162-
*,
163-
by_alias: bool = True,
164-
ref_template: str = '#/$defs/{model}',
165-
**dumps_kwargs: Any
166-
) -> str: ... # inherited from pydantic.main.BaseModel.schema_json>
167-
<@classmethod @typing_extensions.deprecated('The `validate` method is deprecated; use `model_validate` instead.', category=None) class def validate(cls, value: Any) -> Self: ... # inherited from pydantic.main.BaseModel.validate>
168-
<@classmethod @typing_extensions.deprecated('The `update_forward_refs` method is deprecated; use `model_rebuild` instead.', category=None) class def update_forward_refs(cls, **localns: Any) -> None: ... # inherited from pydantic.main.BaseModel.update_forward_refs>
1696
>
1707
>

0 commit comments

Comments
 (0)