Fissix

24.4.24 · active · verified Thu Apr 16

Fissix is a Python library that monkeypatches and overrides the default behavior of the standard library `lib2to3`. It provides an enhanced and actively maintained version of `lib2to3`, primarily used for transforming Python code, especially for backporting `2to3` fixes for Python 3 codebases. It aims to be a drop-in replacement for `lib2to3`'s code transformation utilities. The current version is 24.4.24, and it often sees updates in conjunction with CPython development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically use `fissix`'s `RefactoringTool` to apply all available code fixers to a given string. This is the core mechanism for transforming Python code using `fissix` without relying on file I/O or the command-line interface.

import io
from fissix.refactor import RefactoringTool, get_all_fix_names

# Get all available fixers provided by fissix
all_fixer_names = get_all_fix_names()

# Create a RefactoringTool instance with the desired fixers.
# By default, get_all_fix_names() includes standard 2to3 fixes and fissix enhancements.
tool = RefactoringTool(all_fixer_names)

# Source code to transform
original_code = """
print "Hello, world!"
if True:
    pass # A comment
"""

# Apply the transformation to the string.
# refactor_string returns a Node object representing the transformed code tree.
transformed_tree = tool.refactor_string(original_code, "<string>")

# Convert the transformed tree back to a string representation
transformed_code = str(transformed_tree)

print("Original code:\n" + original_code)
print("\nTransformed code:\n" + transformed_code)

view raw JSON →