This probably has more to do with style and preference than anything else, but ... I have a different attitude to my documentation: I always write docstring according to the expected input in the context of the program .
Example: if I wrote a function that expects to go through the keys of a dictionary and ignore its values, I write:
arg : a dictionary of...
even if for e in arg: will work with other iterators. I decided to do this because, in the context of my code, I don’t care whether the function will still work ... I don’t care if anyone reading the documentation understands how this function is intended to be used.
On the other hand, if I write a utility function that can handle a wide range of design iterations, I can do one of these two ways:
- indicate what exception will be under certain conditions [ex: "Raise TypeError if iterability cannot be repeated more than once"]
- do some preprocessing of the arguments , which will make the function compatible with iterations "only once."
In other words, I try either to make my function strong enough to handle extreme cases, or to be very frank about its limitations .
Again: there is nothing wrong with what you want to do, but I think this is one of the cases where “ explicit is better than implicit ”: the documentation that mentions “reusable iteration” is definitively accurate, but the adjective can be easy missed.
NTN!
source share