or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

checker-system.mdcore-api.mdindex.mdmessage-types.mdreporter-system.md
tile.json

tessl/pypi-pyflakes

Static analysis tool that detects errors in Python code without importing it.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyflakes@3.4.x

To install, run

npx @tessl/cli install tessl/pypi-pyflakes@3.4.0

index.mddocs/

Pyflakes

Pyflakes is a static analysis tool that detects errors in Python code without importing it, making it safe and fast. It analyzes programs by parsing source files and detects various programming errors like undefined variables, unused imports, and syntax issues. Unlike other linters, Pyflakes focuses solely on error detection without complaining about code style, maintaining a strict philosophy of minimizing false positives.

Package Information

  • Package Name: pyflakes
  • Language: Python
  • Installation: pip install pyflakes
  • Version: 3.4.0
  • Python Support: 3.9+

Core Imports

import pyflakes.api
import pyflakes.checker
import pyflakes.reporter
import pyflakes.messages

For basic usage:

from pyflakes.api import check, checkPath, checkRecursive
from pyflakes.reporter import Reporter

Basic Usage

import pyflakes.api

# Check a code string
code = """
import os
x = 1
print(y)  # This will be flagged as undefined
"""
warnings = pyflakes.api.check(code, 'example.py')
print(f"Found {warnings} warnings")

# Check a file
warnings = pyflakes.api.checkPath('myfile.py')

# Check multiple paths recursively
from pyflakes.reporter import _makeDefaultReporter
reporter = _makeDefaultReporter()
warnings = pyflakes.api.checkRecursive(['src/', 'tests/'], reporter)

Architecture

Pyflakes uses a multi-layered architecture:

  • API Layer: High-level functions for checking code strings, files, and directories
  • Checker: Core analysis engine that walks the AST and maintains scope information
  • Messages: Structured error/warning types for different kinds of issues
  • Reporter: Output formatting system for presenting results to users
  • Bindings & Scopes: Internal representation of variable bindings and code scopes

This design enables Pyflakes to safely analyze Python code without importing it while maintaining detailed scope information to minimize false positives.

Capabilities

Core API Functions

Primary interface for checking Python code, supporting code strings, individual files, and recursive directory analysis. These functions provide the main entry points for integrating Pyflakes into development workflows.

def check(codeString: str, filename: str, reporter=None) -> int: ...
def checkPath(filename: str, reporter=None) -> int: ...
def checkRecursive(paths: list, reporter) -> int: ...
def iterSourceCode(paths: list): ...
def isPythonFile(filename: str) -> bool: ...
def main(prog=None, args=None): ...

Core API

Checker System

Advanced code analysis engine that performs AST-based static analysis with comprehensive scope tracking, binding management, and AST node handling. The Checker class provides fine-grained control over the analysis process with 65+ methods covering all Python AST node types.

class Checker:
    def __init__(self, tree, filename='(none)', builtins=None, withDoctest='PYFLAKES_DOCTEST' in os.environ, file_tokens=()): ...
    
    # Core attributes and properties
    messages: list
    deadScopes: list
    scopeStack: list
    futuresAllowed: bool
    annotationsFutureEnabled: bool
    
    # Core analysis methods
    def report(self, messageClass, *args, **kwargs): ...
    def handleNode(self, node, parent): ...
    def deferFunction(self, callable): ...
    def addBinding(self, node, value): ...
    
    # All AST node handlers (FUNCTIONDEF, IMPORT, CALL, etc.)
    # Complete binding system (Assignment, Importation, etc.)
    # Complete scope system (ModuleScope, FunctionScope, etc.)

Checker System

Message Types

Comprehensive set of 48 structured warning and error classes representing different types of issues that can be detected in Python code. Each message type provides specific information about the problem and its location.

class Message:
    def __init__(self, filename, loc): ...

class UndefinedName(Message): ...
class UnusedImport(Message): ...
class RedefinedWhileUnused(Message): ...
class FStringMissingPlaceholders(Message): ...
class PercentFormatInvalidFormat(Message): ...
# ... all 48 message types documented

Message Types

Reporter System

Flexible output formatting system for presenting analysis results to users. The Reporter class can be customized to integrate Pyflakes into different development environments and workflows.

class Reporter:
    def __init__(self, warningStream, errorStream): ...
    def unexpectedError(self, filename, msg): ...
    def syntaxError(self, filename, msg, lineno, offset, text): ...
    def flake(self, message): ...

Reporter System