Convert Figma logo to code with AI

PyCQA logopyflakes

A simple program which checks Python source files for errors

1,359
179
1,359
57

Top Related Projects

3,391

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.

38,528

The uncompromising Python code formatter

5,236

It's not just a linter that annoys you!

13,726

A formatter for Python files

30,822

An extremely fast Python linter and code formatter, written in Rust.

13,105

Static Type Checker for Python

Quick Overview

PyCQA/pyflakes is a simple program that checks Python source files for errors, without executing them. It is a static code analysis tool that can help identify common programming errors, such as undefined variables, unused imports, and syntax errors, before the code is run.

Pros

  • Lightweight and Fast: Pyflakes is a lightweight tool that can quickly analyze Python code, making it suitable for use in development workflows and continuous integration pipelines.
  • Comprehensive Error Detection: Pyflakes can detect a wide range of common programming errors, including syntax errors, undefined variables, unused imports, and more.
  • Integrates with Popular Tools: Pyflakes can be integrated with various code editors and development tools, such as Vim, Sublime Text, and Visual Studio Code, making it easy to incorporate into existing workflows.
  • Actively Maintained: The Pyflakes project is actively maintained by the Python Code Quality Authority (PyCQA), ensuring that it stays up-to-date with the latest Python language features and best practices.

Cons

  • Limited Scope: Pyflakes is focused solely on detecting programming errors and does not provide more advanced code analysis features, such as code style checking or code complexity analysis.
  • Lacks Automatic Fixes: While Pyflakes can identify issues in your code, it does not provide automatic fixes or suggestions for resolving the identified problems.
  • Potential False Positives: In some cases, Pyflakes may report issues that are not actually errors, which can require manual inspection and resolution.
  • Python Version Compatibility: Pyflakes may not always keep up with the latest Python language features, which can lead to compatibility issues with newer versions of Python.

Code Examples

Pyflakes is a code analysis tool, so it does not have any specific code examples to provide. However, here's an example of how you might use Pyflakes to check a Python file:

# Check a single file
pyflakes my_file.py

# Check all Python files in a directory
pyflakes .

Getting Started

To get started with Pyflakes, follow these steps:

  1. Install Pyflakes using pip:

    pip install pyflakes
    
  2. Run Pyflakes on a Python file or directory:

    pyflakes my_file.py
    

    or

    pyflakes .
    

    This will analyze the specified file or all Python files in the current directory and report any issues found.

  3. Integrate Pyflakes into your development workflow:

    • Configure your code editor to run Pyflakes automatically on file save or on-demand.
    • Add Pyflakes to your continuous integration (CI) pipeline to catch issues before merging code changes.
    • Use Pyflakes as part of your pre-commit hook to ensure code quality before committing changes.
  4. Customize Pyflakes behavior:

    Pyflakes can be configured using command-line options or a configuration file. For example, you can exclude certain files or directories from the analysis, or configure the severity of reported issues.

    pyflakes --exclude=tests/ .
    

That's the basic getting started guide for using Pyflakes. For more advanced usage and configuration options, refer to the Pyflakes documentation.

Competitor Comparisons

3,391

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.

Pros of Flake8

  • Flake8 is a more comprehensive tool that combines the functionality of multiple linters, including PyFlakes, PEP8, and McCabe complexity checker.
  • Flake8 provides a more extensive set of checks and rules, making it a more robust and thorough code quality tool.
  • Flake8 has a larger community and more active development, ensuring better maintenance and support.

Cons of Flake8

  • Flake8 can be more complex to configure and customize compared to PyFlakes, which has a simpler and more straightforward setup.
  • Flake8 may have a higher overhead due to the additional checks and integrations, which can slow down the linting process.

Code Comparison

PyFlakes:

def example_function(x):
    if x > 0:
        return x
    else:
        return -x

Flake8:

def example_function(x):
    if x > 0:
        return x
    else:
        return -x

The code examples are the same for both PyFlakes and Flake8, as they both focus on identifying potential issues in the code, such as syntax errors, undefined variables, and unused imports.

38,528

The uncompromising Python code formatter

Pros of Black

  • Black is a highly opinionated code formatter that enforces a consistent code style, making it easier to maintain and collaborate on projects.
  • Black is widely adopted in the Python community and is often used as a standard for code formatting.
  • Black is highly configurable, allowing users to customize certain formatting rules to fit their preferences.

Cons of Black

  • Black can be more restrictive than other code formatters, as it enforces a strict set of rules that may not align with a developer's personal coding style.
  • Black can be slower than other code formatters, especially on larger codebases, due to its comprehensive formatting rules.
  • Black may not be suitable for all projects, as it may not be compatible with certain legacy code or frameworks.

Code Comparison

PyCQA/pyflakes:

def foo(x):
    if x > 0:
        return x
    else:
        return -x

psf/black:

def foo(x):
    return x if x > 0 else -x
5,236

It's not just a linter that annoys you!

Pros of Pylint

  • Pylint provides a more comprehensive set of checks and rules for Python code, covering a wider range of potential issues and best practices.
  • Pylint offers more customization options, allowing users to enable or disable specific checks and configure the tool to their specific needs.
  • Pylint integrates with various IDEs and editors, providing real-time feedback and suggestions for code improvements.

Cons of Pylint

  • Pylint can be more complex to set up and configure, especially for larger projects or teams with specific requirements.
  • Pylint's output can be more verbose and overwhelming, especially for beginners or small projects.
  • Pylint's performance may be slower compared to Pyflakes, especially on larger codebases.

Code Comparison

Pyflakes:

def example_function(x):
    if x > 0:
        return x
    else:
        return -x

Pylint:

def example_function(x):
    """
    This is an example function.

    Args:
        x (int): The input value.

    Returns:
        int: The absolute value of x.
    """
    if x > 0:
        return x
    else:
        return -x

The Pylint version includes a docstring that provides more detailed information about the function, which can be useful for code documentation and maintainability.

13,726

A formatter for Python files

Pros of YAPF

  • YAPF is a powerful code formatter that can automatically format Python code to adhere to the PEP 8 style guide.
  • YAPF is highly configurable, allowing users to customize the formatting rules to their preferences.
  • YAPF is actively maintained and developed by the Google team, ensuring regular updates and improvements.

Cons of YAPF

  • YAPF may not be as widely adopted as other Python linting tools, such as Pyflakes, which have a larger user base.
  • YAPF's focus on formatting may not address all the code quality issues that Pyflakes can detect, such as syntax errors and undefined variables.
  • YAPF's configuration options can be complex, making it more challenging for beginners to set up and use effectively.

Code Comparison

Pyflakes:

import os

def my_function(x):
    if x > 0:
        return x
    else:
        return -x

YAPF:

import os

def my_function(x):
    if x > 0:
        return x
    else:
        return -x

In this example, both Pyflakes and YAPF produce the same formatted code, as the code is already well-formatted and adheres to PEP 8 guidelines. However, Pyflakes would also perform additional checks, such as detecting syntax errors or undefined variables, which YAPF does not.

30,822

An extremely fast Python linter and code formatter, written in Rust.

Pros of Ruff

  • Ruff is a significantly faster linter compared to Pyflakes, with reported speed improvements of up to 10x.
  • Ruff supports a wider range of Python versions, including Python 3.7 and above, making it more versatile.
  • Ruff provides a more comprehensive set of checks and rules, covering a broader range of code quality and style issues.

Cons of Ruff

  • Ruff is a newer project compared to Pyflakes, which has been around for a longer time and has a more established user base.
  • The configuration options in Ruff may be more complex and less intuitive for users who are familiar with Pyflakes.
  • Ruff may have fewer third-party integrations and plugins compared to Pyflakes, which has had more time to build a larger ecosystem.

Code Comparison

Pyflakes (PyCQA/pyflakes):

def example_function(x):
    if x > 0:
        return x
    else:
        return -x

Ruff (astral-sh/ruff):

def example_function(x):
    if x > 0:
        return x
    return -x

The key difference in the code comparison is that Ruff's version of the example_function is more concise, using a single return statement for the else case, while Pyflakes' version uses a separate else block.

13,105

Static Type Checker for Python

Pros of Pyright

  • Pyright provides more advanced type checking and analysis features compared to Pyflakes, including support for type annotations, type inference, and type checking for complex Python constructs.
  • Pyright is actively maintained and developed by Microsoft, with a larger team and more resources behind it compared to Pyflakes.
  • Pyright has better integration with popular IDEs like Visual Studio Code, providing a more seamless developer experience.

Cons of Pyright

  • Pyright is a newer tool compared to Pyflakes, which has been around for a longer time and has a more established user base.
  • Pyright may have a steeper learning curve for developers who are already familiar with Pyflakes and its simpler approach to linting.
  • Pyright is a standalone tool, while Pyflakes is part of the larger PyCQA ecosystem, which may provide more integration and tooling options.

Code Comparison

Pyflakes (PyCQA/pyflakes):

def example():
    x = 1
    y = 2
    return x + y

Pyright (microsoft/pyright):

def example() -> int:
    x: int = 1
    y: int = 2
    return x + y

The key differences are:

  • Pyright uses type annotations, while Pyflakes does not.
  • Pyright infers the types of x and y, while Pyflakes does not.
  • Pyright explicitly declares the return type of the function, while Pyflakes does not.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

======== Pyflakes

A simple program which checks Python source files for errors.

Pyflakes analyzes programs and detects various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It's also much faster.

It is available on PyPI <https://pypi.org/project/pyflakes/>_ and it supports all active versions of Python: 3.8+.

Installation

It can be installed with::

$ pip install --upgrade pyflakes

Useful tips:

  • Be sure to install it for a version of Python which is compatible with your codebase: python#.# -m pip install pyflakes (for example, python3.10 -m pip install pyflakes)

  • You can also invoke Pyflakes with python#.# -m pyflakes . if you want to run it for a specific python version.

  • If you require more options and more flexibility, you could give a look to Flake8_ too.

Design Principles

Pyflakes makes a simple promise: it will never complain about style, and it will try very, very hard to never emit false positives.

Pyflakes is also faster than Pylint_. This is largely because Pyflakes only examines the syntax tree of each file individually. As a consequence, Pyflakes is more limited in the types of things it can check.

If you like Pyflakes but also want stylistic checks, you want flake8_, which combines Pyflakes with style checks against PEP 8_ and adds per-project configuration ability.

Mailing-list

Share your feedback and ideas: subscribe to the mailing-list <https://mail.python.org/mailman/listinfo/code-quality>_

Contributing

Issues are tracked on GitHub <https://github.com/PyCQA/pyflakes/issues>_.

Patches may be submitted via a GitHub pull request. If you are comfortable doing so, please rebase your changes so they may be applied to main with a fast-forward merge, and each commit is a coherent unit of work with a well-written log message. If you are not comfortable with this rebase workflow, the project maintainers will be happy to rebase your commits for you.

All changes should include tests and pass flake8_.

.. image:: https://github.com/PyCQA/pyflakes/workflows/Test/badge.svg :target: https://github.com/PyCQA/pyflakes/actions :alt: GitHub Actions build status

.. _Pylint: https://pylint.pycqa.org/ .. _flake8: https://pypi.org/project/flake8/ .. _PEP 8: https://www.python.org/dev/peps/pep-0008/ .. _rebase your changes: https://git-scm.com/book/en/v2/Git-Branching-Rebasing .. _GitHub pull request: https://github.com/PyCQA/pyflakes/pulls

Changelog

Please see NEWS.rst <https://github.com/PyCQA/pyflakes/blob/main/NEWS.rst>_.