by mhils · 1y ago · 0 comments
I much prefer the way Rust did it, so just a separate type of comment-prefix for docstrings. In Rust a regular comment may be
// this is a comment
foo = 1.5;
while a docstring is simply /// this shows up in docs
foo = 1.5;
with //! for docstrings at a module level. This is elegant. This is simple. It is a pythonic solution. Treating comments below a variable declaration implicity as a docstring is not. At the beginning of class or function declarations, ok (although I also would have prefered that to be above the declaration), but this.. I need a drink. my_var = 5
"documentation for my_var"
def my_func():
"documentation for my_func"
also worth noting, pdoc didn't invent this design pattern, sphinx did (or perhaps something preceding sphinx?)and since sphinx is the documentation tool of choice by the python core devs to document python itself, i have to assume they've given this design pattern at least tacit approval... :shrug: