Perflint: Pylint Extension for Performance Anti-patterns

0.8.1 · active · verified Thu Apr 16

Perflint is an extension for Pylint that identifies performance anti-patterns in Python code, helping developers optimize their applications by flagging common inefficiencies. It is currently in early beta, version 0.8.1, and may produce false positives. The project is actively maintained with a focus on enhancing code performance through static analysis.

Common errors

Warnings

Install

Imports

Quickstart

Save the code above as `my_module.py`. Then run Perflint as a Pylint plugin. It will highlight performance anti-patterns like global lookups in loops, unnecessary list casting, and inefficient dictionary iteration.

import os

def process_data(items):
    # W8202: Global name usage in a loop
    # os.environ is a global lookup; cache it outside the loop for performance.
    for item in items:
        value = os.environ.get(item, 'default') # This will trigger W8202
        print(value)

def unnecessary_list_cast_example(data):
    # W8101: Unnecessary use of list() on an already iterable type
    for x in list(data): # data is already iterable, no need for list()
        print(x)

def incorrect_dict_iterator_example(dictionary):
    # W8102: Incorrect iterator method for dict
    for _, value in dictionary.items(): # If only values are needed, use .values()
        print(value)

if __name__ == '__main__':
    my_items = ['HOME', 'PATH']
    process_data(my_items)
    my_tuple = (1, 2, 3)
    unnecessary_list_cast_example(my_tuple)
    my_dict = {'a': 1, 'b': 2}
    incorrect_dict_iterator_example(my_dict)

view raw JSON →