Wemake-python-styleguide: Forbid multiline comments

Created on 27 Jul 2018  路  1Comment  路  Source: wemake-services/wemake-python-styleguide

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)
help wanted starter rule request

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_magic body), then I think this info _should_ go to the docstring.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobolevn picture sobolevn  路  4Comments

sobolevn picture sobolevn  路  3Comments

sobolevn picture sobolevn  路  5Comments

sobolevn picture sobolevn  路  4Comments

hangtwenty picture hangtwenty  路  5Comments