88from pathlib import Path
99from packaging .version import parse as parse_version
1010
11+ import peewee as pw
12+
1113import flexeval
1214
1315sys .path .append (os .path .abspath ("." ))
@@ -168,6 +170,12 @@ def linkcode_resolve(domain, info):
168170nb_merge_streams = True
169171
170172autosummary_generate = True
173+ # Don't let numpydoc inject its own per-class "Methods"/"Attributes" summary
174+ # tables. They duplicate the member documentation autodoc already renders below,
175+ # and for our peewee models they list every inherited peewee.Model method
176+ # (save, select, bulk_create, ...) as noise. Disabling this also avoids the
177+ # "stub file not found" warnings those tables' :toctree: would otherwise emit.
178+ numpydoc_show_class_members = False
171179autodoc_typehints = "signature"
172180autodoc_default_options = {
173181 "members" : True ,
@@ -178,18 +186,29 @@ def linkcode_resolve(domain, info):
178186}
179187
180188
181- def skip_inherited_members (app , what , name , obj , skip , options ):
182- # Skip members if they are inherited (not defined on the class itself)
183- if what == "class" :
184- # The object is the class being documented
185- cls = obj
186- if hasattr (cls , "__dict__" ):
187- # If the member name is NOT in the class dict, it's inherited
188- if name not in cls .__dict__ :
189- return True # skip inherited member
190- return skip # otherwise use default behavior
189+ def skip_peewee_internals (app , what , name , obj , skip , options ):
190+ """Hide peewee-generated noise from the API docs.
191+
192+ peewee's model metaclass adds two kinds of members to every model class
193+ that aren't useful in the generated reference:
194+
195+ - a per-model ``DoesNotExist`` exception (e.g. ``MetricDoesNotExist``), and
196+ - a ``<fk>_id`` alias for every foreign key (e.g. ``dataset_id`` alongside
197+ ``dataset``). The alias shares the same ``Field`` object as the FK, whose
198+ ``.name`` is the FK field name, so we can detect it by name mismatch.
199+
200+ Genuine fields and methods are left untouched. (Inherited members are
201+ excluded separately via ``inherited-members: False`` below — note that
202+ peewee's per-model ``DoesNotExist`` and ``_id`` accessors are defined on the
203+ model class itself, not inherited, which is why they need explicit skipping.)
204+ """
205+ if name == "DoesNotExist" :
206+ return True
207+ if isinstance (obj , pw .ForeignKeyField ) and name != obj .name :
208+ return True
209+ return skip
191210
192211
193212def setup (app ):
194- app .connect ("autodoc-skip-member" , skip_inherited_members )
213+ app .connect ("autodoc-skip-member" , skip_peewee_internals )
195214 app .connect ("builder-inited" , vignettes .generate_custom_stubs )
0 commit comments