Multiline comments show as warning

When I make a multiline comment above a class or method definition, PyCharm warns "Statement has no effect".

The only time it will recognize this as a comment is when the multiline comment is at the top of the file before any import statements.

What can I do to fix this?



Attachment(s):
error.png
0
4 comments
Avatar
Permanently deleted user

Hello Darren,

From a Python language point of view, these warnings are correct. The multiline comment at the top of a file --before any statement-- is the module docstring (refer to http://www.python.org/dev/peps/pep-0257/#id17). The multiline comments which are not recognised as docstrings (because they simple aren't) are in fact only string expressions which, as they are not assigned to anything or used in a function call, do not have any effect. The inspection works correctly.

I agree that it would be handy to have an option to switch the warnings off in this special case. Maybe you want to file a request in YouTrack, for example "Implement option to ignore warnings for multiline comments"?

Volker

0
Avatar
Permanently deleted user

Having a configuration option that referred to "multiline comments" would be a bit confusing to many of us, as Python doesn't *have* multiline comments; as you've already pointed out, these are multiline strings.  You could still have an option for disabling this inspection on multiline strings, but I expect most Python developers will frown upon that stylistic choice.

0
Avatar
Permanently deleted user

keturn wrote:

Having a configuration option that referred to "multiline comments" would be a bit confusing to many of us, as Python doesn't *have* multiline comments; as you've already pointed out, these are multiline strings.  You could still have an option for disabling this inspection on multiline strings, but I expect most Python developers will frown upon that stylistic choice.

I'd second an additional Inspection setting to toggle enabling/disabling  "Statement has no effect" inspections for multline strings, not just  any and all statements.

Kevin is spot on, but then that's why it would be a preference would it not?  I myself got annoyed at the barrage of "Statement has no effect" warnings and opted to disable that inspection.  Ideally, I'd love to leave the inspection in play for non-strings.

0
Avatar
Permanently deleted user

darrennix wrote:

When I make a multiline comment above a class or method definition, PyCharm warns "Statement has no effect".

The only time it will recognize this as a comment is when the multiline comment is at the top of the file before any import statements.

What can I do to fix this?

I turned off the inspection under Settings \ Project Settings \ Inspections \ Python.

Cheers,

Rob

0

Please sign in to leave a comment.