0

I have a simple attrs data class:

from attrs import frozen

@frozen
class Person
    raw: str

I document it with the simplest *.rst file:

.. autoclass:: api.main.person.Person
   :members:
   :exclude-members: __init__

but if I need to remove __eq__, __hash__ etc. as well, Is there a better way?

mzjn
  • 48,958
  • 13
  • 128
  • 248
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
  • Have you set `autodoc_default_options` in conf.py? https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_default_options – mzjn Aug 11 '22 at 16:00
  • @mzjn I actually don't *always* want to exclude `__init__` (`__eq__` etc.) ... only if they were bolier(ly)-plated by attrs – OrenIshShalom Aug 11 '22 at 16:27
  • Does it help if you add the `:no-special-members:` option to `autoclass`? – mzjn Aug 11 '22 at 16:40
  • no, it doesn't, I still see the `__init__` ... I wonder if you can somehow do an attrs "trick" to remove their auto-generated docstring: `Method generated by attrs for class Person.` ... If I can remove that then I'm done because sphinx (can) ignore methods without doc strings – OrenIshShalom Aug 11 '22 at 16:46
  • I am trying to understand why you get `__eq__` etc in the output. I don't see them unless I add `:special-members:`. – mzjn Aug 11 '22 at 16:53
  • ah sorry, I was maybe unclear - I have *many* attrs classes, each with its own set of auto generated methods. I want auto-generated methods to not appear in the sphinx doc – OrenIshShalom Aug 11 '22 at 17:00
  • To me, it looks as if the default is to exclude the autogenerated methods from the output. I cannot explain why it doesn't work for you. – mzjn Aug 11 '22 at 17:07
  • I'm seeing the same behaviour as reported by @OrenIshShalom. Does anyone have a solution for this? For example, does Sphinx have any way to exclude docstrings which match a given regex? Or (slightly lower level) a hook through which docstrings are passed, so that I could write my own function which looks for "generated by attrs" and delete the entire docstring if it matches. – Gareth Stockwell Mar 11 '23 at 17:36

0 Answers0