When a comment exceeds a single line it should be moved into the documentation.
Here's an example. Don't:
def _some_magic():
result_part = run_some()
# We only store a part of the result here, because we need to update it in some cases
# like ConnectionError or HttpError. Only some clients use this method.
return update_result(result_part)
Do:
def _some_magic():
"""
Runs some magic. Makes people happy.
We only store a part of the result here, because we need to update it in some cases
like ConnectionError or HttpError. Only some clients use this method.
"""
result_part = run_some()
return update_result(result_part)
Also fine:
def _some_magic():
result_part = run_some() # ConnectionError or HttpError might happen
return update_result(result_part)
I would argue about your examples.
The "don't" snippet's comment actually describes an implementation detail that is hardly ever observed by a user. That's why I don't think it should go straight to the docstring.
The "Also fine" example's comment actually describes something that _can_ outlive the function's scope: exceptions. If this is important (to a point that you are aware of these exceptions and explicitly do not catch them in _some_magic body), then I think this info _should_ go to the docstring.
Most helpful comment
I would argue about your examples.
The "don't" snippet's comment actually describes an implementation detail that is hardly ever observed by a user. That's why I don't think it should go straight to the docstring.
The "Also fine" example's comment actually describes something that _can_ outlive the function's scope: exceptions. If this is important (to a point that you are aware of these exceptions and explicitly do not catch them in
_some_magicbody), then I think this info _should_ go to the docstring.