2

Assuming I have a class that implements the Sequence interface, i.e. has __len__ and __getitem__ methods, what is the recommended way to document this? Is an informal description in the classes docstring enough, should I subclass collections.abc.Sequence or do something else entirely?

gmolau
  • 2,815
  • 1
  • 22
  • 45
  • If you subclass `Sequence`, you automatically get implementations of `__contains__`, `__iter__`, `__reversed__`, `index`, and `count`. Do you want that? – Alex Hall May 13 '18 at 19:05
  • Originally I didn't because the sequence is just one attribute of the class that I wanted to forward the sequence access methods to. But I forgot that subclassing would give me Reversible and Collection as well, in that case it makes probably more sense to just subclass rather than implementing all of their methods manually. That still leaves the question how to document interface implementation though. – gmolau May 13 '18 at 19:47

0 Answers0