Last updated: Apr 10, 2024
Reading time·4 min
The Pylint warning "String statement has no effect pylint(pointless-string-statement)" is shown for multiple reasons:
#
instead).Here is an example of when the warning is shown.
"""This is a docstring that describes what the module does""" # ⛔️ String statement has no effect pylint(pointless-string-statement) """This string statement is pointless""" site = 'bobbyhadz.com' print(site)
The first line in the file is the docstring (documentation string).
It describes what the module does.
However, the second triple-quoted string does nothing.
You can remove the second triple-quoted string to resolve the issue.
But they also enable us to:
example = """ bobby hadz com """ # bobby # hadz # com print(example)
The warning is commonly shown when you place your docstring below the import statements.
import sys # ⛔️ String statement has no effect pylint(pointless-string-statement) """This is a docstring that describes what the module does""" print(sys) site = 'bobbyhadz.com' print(site)
Notice that the documentation string is placed below the import sys
line in
the code sample.
To resolve the issue, move the docstring to the first line of the module, above all import statements.
"""This is a docstring that describes what the module does""" import sys print(sys) site = 'bobbyhadz.com' print(site)
Another common cause of the warning is trying to use a triple-quoted string to comment out lines in your Python module.
site = 'bobbyhadz.com' print(site) # ⛔️ String statement has no effect pylint(pointless-string-statement) """ First comment line Second comment line Third comment line """
The example tries to use a triple-quoted string as a multiline comment which causes the warning.
Python doesn't have syntax for multiline comments, so you have to prefix each
line with a hash symbol #
.
site = 'bobbyhadz.com' print(site) # First comment line # Second comment line # Third comment line
Your comments can be placed on the same line or a separate line.
However, all comments start with a hash #
.
site = 'bobbyhadz.com' # Comment on same line print(site) # This is a comment on a separate line
If you want to use multiline strings as multiline comments, you have to disable
the pointless-string-statement
Pylint rule.
One way to disable the rule is in your pylintrc
file.
Open the file and search for the disable=
key.
Add the pointless-string-statement
rule to the disabled Pylint rules.
disable=pointless-string-statement,
Now you can use multiline strings as multiline comments without getting any Pylint warnings.
site = 'bobbyhadz.com' print(site) """First comment line Second comment line Third comment line"""
Unless multiline strings are used as docstrings, they don't generate any code.
An alternative way to disable the pointless-string-statement
Pylint rule is to
do it directly in Visual Studio Code's
settings.json file.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
python.linting.pylintArgs
property in your settings.json
file to
an array that disables the pointless-string-statement
warning.{ "python.linting.pylintArgs": [ "--disable=pointless-string-statement" ], }
The format for each array entry is "--disable=PYLINT_WARNING_NAME"
.
Make sure to remove the trailing comma if the property comes last.
After disabling the rule, you will be able to use triple-quoted strings as multiline comments without any issues.
You can also only disable the pointless-string-statement
rule for your current
Visual Studio Code project.
In the root directory of your project, create a .vscode
folder.
Create a settings.json
file in the .vscode
folder.
Add the following code to your settings.json
file.
{ "python.linting.pylintArgs": [ "--disable=pointless-string-statement" ] }
The configuration properties you add to your local .vscode/settings.json
file
are only applied to the current project and overwrite any global configuration.
Once you've disabled the pointless-string-statement
rule, you can use
triple-quoted strings as multiline comments without any issues.
site = 'bobbyhadz.com' print(site) """First comment line Second comment line Third comment line"""
I've written a detailed guide on how to disable specific Pylint warnings.
If you need to disable the "Missing module docstring" Pylint warning, check out the following article.