If you are using pre-commit, the Pylint errors will be the same as if using Pylint alone. We highly recommend using pre-commit. For more information, check out this page: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code

Pylint has a significant number of checks it can perform. Many are disabled for the purposes of Adafruit Learn guide code. The important checks for this guide are the ones Adafruit does not disable. You've already downloaded the Pylint configuration file and the example. You've completed the first run of Pylint and received an error. Now you'll learn how to read the Pylint output and resolve a few common errors.

Pylint Output

Pylint has a standard format to its output. When there is a syntax error, it will not show a code rating.

Depending on your version of Pylint, you may or may not see the first line informing you what .pylintrc configuration file you're using. This allows you to verify that you're using the one you intended to. Pylint will first look in the current working directory for a .pylintrc to use. That is why it's easiest to copy the file into your working directory when running Pylint.

The next line, ************* Module pylint_example, begins with a series of asterisks and then identifies which file (Module) you're linting. In this case, you're linting pylint_example.py, so the line ends with pylint_example. If you were linting more than one file at once and more than one contained errors, there would be multiple instances of this line followed by any errors found in each file.

The next section is the most important part: the error list. This is where Pylint lists all the checks that have failed. The errors all follow a standard format. This is the first of three errors:

  • pylint_example.py 15: Line too long (120/100) (line-too-long).

The error lines are composed of the same four key parts:

  1. The file name: pylint_example.py
  2. The line containing the error: 15:
  3. The details of the error: Line too long
  4. The Pylint check name: (line-too-long)

Note that the details and the Pylint check name will not always be the same (as in the third error shown in the image above). Some error details tell you the issue, but not necessarily how to resolve it, e.g. the first two errors shown in the image above. Others explicitly tell you how to resolve the error, e.g. the third error shown in the image above. The next section will explain how to work through each type of error.

Once syntax errors have been resolved, your code will receive a rating out of 10. The error is followed by a line of - dashes to separate the rating from the errors. The last line is the code rating:

  • Your code has been rated at 9.06/10

Each error is worth a negative number of "points" which are added up and subtracted from 10 to provide the rating. Sometimes the code rating will be negative. Don't worry! It's happened to everyone. Start at the beginning and work your way through it regardless of the rating.

Each time you run Pylint after the first time, it compares the current score to the previous score. Sometimes your score will go up, sometimes your score will go down. Each successive run's score line will look something like this:

  • Your code has been rated at 9.69/10 (previous run: 9.06/10, +0.62)

The score is irrelevant to the actual process of linting your code. It is not the important part of the Pylint output. The important part is the list of errors for you to resolve. Focus on that list and you'll soon have your code linted perfectly.

Working Through Pylint Errors

Now that you know how to read the output, it's finally time to start working through the Pylint errors. 

Be aware that Pylint may not show you all the errors at once. It will cascade fail by returning one error and then, once that error is resolved, returning another series of errors. This is why it's important to run Pylint locally, otherwise you'll be waiting for the remote linter to run each time before you can start working on the next set of errors.

Let's get started!

Error: inconsistent use of tabs and spaces

The first error is a syntax error on line 32: inconsistent use of tabs and spaces in indentation (, line 32) (syntax-error). The example has a mix of tabs and spaces in the same if/else statement. Knowing spaces were used for the majority of the code, it's clear here that a tab managed to sneak in. There is a tab before the else on line 32. Replace it with four spaces to match the rest of the code.

Errors: line too long, trailing whitespace, wrong import order

Now that you've resolved the syntax error, Pylint has found three linting errors.

You'll start with the first error:

  • pylint_example.py 15: Line too long (106/100) (line-too-long)

Line 15 is too long. In this case, there doesn't need to be much more explanation, so Pylint keeps it simple. The fix is easy enough. After the first 10000, separate the rest onto a new line, as follows:

circuit_playground_temperature = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
10000, 25, 3950)

Now, look at the second error:

  • pylint_example.py 44: Trailing whitespace (trailing-whitespace)

There is trailing whitespace on line 44. Again, Pylint keeps the details simple. If you look at the code, you'll see that there are four spaces on line 44 where there should be none. Delete those spaces.

Now, you'll address the last error:

  • pylint_example.py 5: standard import "import time" should be placed before "import board" (wrong-import-order)

The libraries are imported in the wrong order. In this error, the details explicitly state what needs to happen to resolve the error. Currently found on line 5, import time should be placed before import board. Rearrange the import list as follows to resolve this error:

import time
import board
import digitalio
import adafruit_lis3dh
import touchio
import neopixel
import adafruit_thermistor

Ok! You've addressed all of the errors Pylint found on this run. It's time to run Pylint again.

Error: bad continuation

Pylint has found one more error:

  • pylint_example.py 16: Wrong continued indentation (add 64 spaces).
    10000, 25, 3950)
    ^                                             | (bad-continuation)

This error is on line 16. That's the line we split off from line 15 to resolve the line too long error. The issue is that the indentation used on line 16 is incorrect. This error's details are quite clear on how to resolve it: you need to indent the line by 64 spaces. Lines 15 and 16 should look like the following when the error is addressed:

circuit_playground_temperature = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
                                                                10000, 25, 3950)

Once that line is fixed up, it's time to run Pylint again.

Excellent! We've worked through all the errors in our code, and Pylint is happy! 10 out of 10!

This guide was first published on Aug 23, 2019. It was last updated on Nov 27, 2023.

This page (Pylint Errors) was last updated on Aug 14, 2019.

Text editor powered by tinymce.