.pylintrc

Pylint checks for many things. Some of them may be more important than others for your application. You can create a file that allows you to tell Pylint to ignore certain checks. This file is called .pylintrc.

Adafruit uses two different .pylintrc files: one for library code, and one for Learn guide code examples. The library code .pylintrc is much stricter than the one for code examples. This was done to ensure readability over strict compliance.

For this guide, you're going to use the Learn code .pylintrc. First, download the file from here and save it to the folder that will contain your example. The easiest way to ensure that Pylint uses the desired .pylintrc file is to place it in the same working directory as your code.

Open the file into an editor to take a look at the configuration options. The part you'll be most likely to configure is the second section under [MESSAGES CONTROL], beginning with # Disable the message, report, category or checker with the given id(s). This section allows you to disable specific checks. As you can see, for Learn examples a significant number of them have been disabled:

Download: file
disable=
    too-many-instance-attributes,
    len-as-condition,
    too-few-public-methods,
    anomalous-backslash-in-string,
    no-else-return,
    simplifiable-if-statement,
    too-many-arguments,
    duplicate-code,
    no-name-in-module,
    no-member,
    print-statement,
    parameter-unpacking,
    unpacking-in-except,
    old-raise-syntax,
    backtick,
    long-suffix,
    old-ne-operator,
    old-octal-literal,
    import-star-module-level,
    raw-checker-failed,
    bad-inline-option,
    locally-disabled,
    locally-enabled,
    file-ignored,
    suppressed-message,
    useless-suppression,
    deprecated-pragma,
    apply-builtin,
    basestring-builtin,
    buffer-builtin,
    cmp-builtin,
    coerce-builtin,
    execfile-builtin,
    file-builtin,
    long-builtin,
    raw_input-builtin,
    reduce-builtin,
    standarderror-builtin,
    unicode-builtin,
    xrange-builtin,
    coerce-method,
    delslice-method,
    getslice-method,
    setslice-method,
    no-absolute-import,
    old-division,
    dict-iter-method,
    dict-view-method,
    next-method-called,
    metaclass-assignment,
    indexing-exception,
    raising-string,
    reload-builtin,
    oct-method,
    hex-method,
    nonzero-method,
    cmp-method,
    input-builtin,
    round-builtin,
    intern-builtin,
    unichr-builtin,
    map-builtin-not-iterating,
    zip-builtin-not-iterating,
    range-builtin-not-iterating,
    filter-builtin-not-iterating,
    using-cmp-argument,
    eq-without-hash,
    div-method,
    idiv-method,
    rdiv-method,
    exception-message-attribute,
    invalid-str-codec,
    sys-max-int,
    bad-python3-import,
    deprecated-string-function,
    deprecated-str-translate-call,
    import-error,
    missing-docstring,
    invalid-name,
    bad-whitespace,
    consider-using-enumerate

Note: In the file you downloaded, the disable= checks are all on a single line. The list provided above is formatted onto separate lines to make it easier to read. Both are valid, functional formats for a .pylintrc disable= configuration.

If you'd like to know what each of these does, check out the Pylint documentation.

The documentation also includes the rest of the available checks. If you'd like to configure your own .pylintrc, you would add to or remove from the list any of the checks you'd rather have included or excluded. However, you will want to use the two provided as-is when working with example code intended for Adafruit libraries or Learn guides.

For this guide, the important checks are the ones that haven't been disabled above. Those are the rules that you still have to follow for the Pylint checks to pass. Before continuing, make sure you saved the .pylintrc you downloaded to same directory as your code. Next you'll learn how to run Pylint on your code.

This guide was first published on Aug 23, 2019. It was last updated on Aug 23, 2019. This page (.pylintrc) was last updated on Mar 30, 2020.