Disable the 'Missing module docstring' Pylint warning

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
3 min

banner

# Disable the 'Missing module docstring' Pylint warning

The "Missing module docstring pylint(missing-module-docstring)" warning is shown when a module has no docstring.

missing module docstring pylint

One way to get rid of the warning is to specify a documentation string on the first line of the module.

main.py
"""Module has a function that prints the name of my site""" def print_site_name(): site = 'bobbyhadz.com' print(site)

Note that empty modules don't require a docstring.

The module's docstring is specified on the first line using a triple-quoted string.

If you add the code above to a Python file, you will see that the "Missing module docstring" warning is no longer shown.

The module's documentation string is used to describe the purpose of the Python module.

However, you might now be seeing the warning "Missing function or method docstring pylint(missing-function-docstring)".

missing function or method docstring

You can add a documentation string below the function's definition line def abc(): to describe what the function does.

main.py
"""Module has a function that prints the name of my site""" def print_site_name(): """Function printing the name of my site""" site = 'bobbyhadz.com' print(site)

Now the main.py module has a documentation string and a docstring for the function, so the warnings are no longer shown.

If you work with classes, you might get the "Missing class docstring pylint(missing-class-docstring)" Pylint warning.

missing class docstring pylint

You have to add a documentation string to the class just like in the previous examples.

main.py
"""Module has a function that prints the name of my site""" class Employee(): """Used to create Employee instances""" def __init__(self, name): self.salary = 100 self.name = name

Make sure to also set a docstring in your methods.

main.py
"""Module has a function that prints the name of my site""" class Employee(): """Used to create Employee instances""" def __init__(self, name): self.salary = 100 self.name = name def print_name(self): """Prints the name of the employee instance""" print(self.name)

The print_name method of the Employee class also has a documentation string.

# Disabling the 'Missing module docstring' warning in pylintrc

You can also disable the "Missing module docstring" warning in your pylintrc file.

In your pylintrc file, find the disable key and add the following 3 values:

  • missing-module-docstring
  • missing-function-docstring
  • missing-class-docstring
pylintrc
disable=missing-module-docstring, missing-function-docstring, missing-class-docstring

disable missing module docstring warning

The example disables the 3 warnings but you can adjust this depending on your needs.

After I've saved the pylintrc and restarted Visual Studio Code, no warnings are shown in the following file.

main.py
def print_site_name(): site = 'bobbyhadz.com' print(site) class Employee(): def __init__(self, name): self.salary = 100 self.name = name def print_name(self): print(self.name)

no warnings shown

# Disabling the 'Missing module docstring' warning in Visual Studio Code

You can also disable the warning directly in Visual Studio Code.

  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. Add the python.linting.pylintArgs property to your settings.json file.
settings.json
{ "python.linting.pylintArgs": [ "--disable=missing-module-docstring", "--disable=missing-function-docstring", "--disable=missing-class-docstring" ], }

disable missing module docstring warning in settings json

Note:

  1. Make sure to add the --disable= keys to your existing python.linting.pylintArgs array if it already exists in settings.json.
  2. Make sure to remove the trailing comma if the property comes last.

Save the settings.json file and the missing module docstring warning will be disabled.

If you only want to disable the warning for your current project, use the local .vscode/settings.json file instead.

  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=missing-module-docstring", "--disable=missing-function-docstring", "--disable=missing-class-docstring" ] }

disable missing module docstring warning in local settings json

The properties in your local .vscode/setting.json only apply to the current project and override any global configuration.

If the issue persists, restart Visual Studio Code.

I've also written a detailed, step-by-step guide on how to disable specific Pylint warnings or all warnings in a file.

If you get the warning "String statement has no effect Pylint (pointless-string-statement)", 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.