Open ml-kalju opened 1 month ago
For resolving such edge-case problems, I'm leaning to complicating end-user rather than project code. Unless you want to contrib it?
ignore the
BaseModel
's methods from the documentation
You can achieve this with:
__pdoc__ = dict(
(f'{cls.__name__}.{method}', False)
for method in (BaseModel., 'model_computed_fields', 'model_config')
for cls in (BaseModel, *BaseModel.__subclasses__())
)
or
__pdoc__ = dict(
(f'{cls.__name__}.{method}', False)
for method, _ in inspect.getmembers(BaseModel, inspect.isfunction)
for cls in (BaseModel, *BaseModel.__subclasses__())
)
Note that BaseModel.__subclasses__()
only returns expected result after the extending classes have been created.
I have a module that defines big nested data structure that is based on Pydantic. For the examples below, I use pydantic as an example even though this happens with any base-class. Minimal version is like this.
I would want to use
__pdoc__
variable to ignore theBaseModel
's methods from the documentation, as they appear under each of these classes.However, I don't want to disable inheritance altogether with the
--config
flag, as this is the only case where inherited members are not desired.Expected Behavior
Something like the following removes the documentation for these inherited members from all the classes in the module where this is defined.
Actual Behavior
Produces the following:
UserWarning: __pdoc__-overriden key '*.model_fields' does not exist in module 'MY_MODULE'
And there is no change in documentation.
Steps to Reproduce
pip install pydantic
__pdoc__
parameter as defined in the expected behaviourConfiguration
,ConfA
andConfB
Additional info