String statement has no effect Pylint (pointless-string-statement)

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
4 min

banner

# Table of Contents

  1. String statement has no effect Pylint (pointless-string-statement)
  2. Make sure you haven't placed your docstring below the import statements
  3. Make sure you aren't trying to use a triple-quoted string to comment out lines
  4. Using multiline strings as multiline comments in Python

# String statement has no effect Pylint (pointless-string-statement)

The Pylint warning "String statement has no effect pylint(pointless-string-statement)" is shown for multiple reasons:

  1. Placing your docstring (documentation string) below the import statements.
  2. Adding a triple-quoted string somewhere in your code where it is not serving the purpose of a docstring.
  3. Trying to use a triple-quoted string as a comment (Python doesn't have multiline comments, use # instead).

Here is an example of when the warning is shown.

main.py
"""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)

string statement has no effect pylint

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.

Triple-quotes strings are very similar to basic strings that we declare using single or double quotes.

But they also enable us to:

  • use single and double quotes in the same string without escaping
  • define a multiline string without adding newline characters
main.py
example = """ bobby hadz com """ # bobby # hadz # com print(example)

# Make sure you haven't placed your docstring below the import statements

The warning is commonly shown when you place your docstring below the import statements.

main.py
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)

placing docstring below import statements

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.

main.py
"""This is a docstring that describes what the module does""" import sys print(sys) site = 'bobbyhadz.com' print(site)

warning resolved by moving docstring above import statements

# Make sure you aren't trying to use a triple-quoted string to comment out lines

Another common cause of the warning is trying to use a triple-quoted string to comment out lines in your Python module.

main.py
site = 'bobbyhadz.com' print(site) # ⛔️ String statement has no effect pylint(pointless-string-statement) """ First comment line Second comment line Third comment line """

trying to use a triple quoted string as a multiline comment

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 #.

main.py
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 #.

main.py
site = 'bobbyhadz.com' # Comment on same line print(site) # This is a comment on a separate line

# Using multiline strings as multiline comments in Python

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.

  1. Open the file and search for the disable= key.

  2. Add the pointless-string-statement rule to the disabled Pylint rules.

pylintrc
disable=pointless-string-statement,

add pointless string statement to list of disabled pylint rules

Now you can use multiline strings as multiline comments without getting any Pylint warnings.

main.py
site = 'bobbyhadz.com' print(site) """First comment line Second comment line Third comment line"""

using multiline string as multiline comment

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.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Set the python.linting.pylintArgs property in your settings.json file to an array that disables the pointless-string-statement warning.
settings.json
{ "python.linting.pylintArgs": [ "--disable=pointless-string-statement" ], }

disable pointless string statement pylint rule

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.

  1. In the root directory of your project, create a .vscode folder.

  2. Create a settings.json file in the .vscode folder.

  3. Add the following code to your settings.json file.

.vscode/settings.json
{ "python.linting.pylintArgs": [ "--disable=pointless-string-statement" ] }

disable pointless string statement for current project

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.

main.py
site = 'bobbyhadz.com' print(site) """First comment line Second comment line Third comment line"""

using multiline string as multiline comment

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.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.