Registry / testing / fissix

fissix

JSON →
library24.4.24pypypi✓ verified 92d ago

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.

pip install fissix
INSTALL
IMPORT
SIG · FISSIX
F
fissix
testingpythonv24.4.24
Install
1.7s avg
Import
180ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v24.4.24 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.185s · 19.6MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.175s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RefactoringTool
✓ from fissix.refactor import RefactoringTool
`fissix` provides its own implementation of core `lib2to3` components. While `fissix` monkeypatches `lib2to3`, it's best practice to import directly from `fissix` modules to ensure you're using the enhanced versions, especially for classes like `RefactoringTool`.
main
✓ import fissix.main
The `fissix.main` module provides the command-line interface and entry point, similar to `lib2to3.main`. Use `fissix.main.main()` for command-line-like execution or `RefactoringTool` for programmatic transformations.

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)
Debug
Known issues
breakingFissix monkeypatches the standard library `lib2to3` module upon import. This can lead to unexpected behavior or conflicts if other libraries also attempt to modify `lib2to3` or rely on its exact default implementation before `fissix` is imported.
fix
Ensure `fissix` is imported early in your application's lifecycle if you intend for its monkeypatching to take effect globally. If conflicts arise, isolate `fissix` usage to specific contexts or consider alternatives if strict `lib2to3` behavior is required elsewhere.
affects: All versions
gotcha`fissix` is a fork and enhancement of `lib2to3`. While it aims for full compatibility and improvement, subtle differences in behavior, available fixers, or parsing logic might exist compared to the vanilla `lib2to3` module. Always test thoroughly when migrating or expecting precise `lib2to3` parity.
fix
Review the `fissix` GitHub repository and documentation for specific changes or enhancements. Perform comprehensive regression tests when integrating `fissix` into existing `lib2to3`-reliant projects.
affects: All versions
gotcha`fissix` is primarily designed for transforming Python 3 code or modernizing code that was originally Python 2 but intended for Python 3 environments. It is not a tool to run *on* a Python 2 interpreter to convert Python 2 source code to Python 3.
fix
Ensure you are running `fissix` in a Python 3 environment. Its purpose is to provide an improved code transformation framework within Python 3.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'lib2to3.fixes' has no attribute 'fix_xxx'
You are attempting to access a fixer or utility module that is either specific to `fissix` or has been overridden by `fissix`, but you are trying to import it directly from the original `lib2to3.fixes` namespace.
fix
While `fissix` monkeypatches `lib2to3`, it's best to explicitly import fixers and utilities from `fissix` modules (e.g., `from fissix.fixes import fix_print` or `from fissix.fixer_util import Name`). If using `RefactoringTool`, pass the fully-qualified string name like `'fissix.fixes.fix_print'`.
RuntimeWarning: This application uses the lib2to3 module, which is deprecated in Python 3.x and scheduled for removal in Python 3.12.
`fissix` is built on and extends `lib2to3`. Even when using `fissix`, the underlying (and now deprecated) standard library `lib2to3` module is still utilized, triggering Python's deprecation warning.
fix
This warning is expected and generally harmless when using `fissix`, as `fissix` aims to maintain and enhance `lib2to3`. It indicates Python's stance on the *standard library* `lib2to3`, not a problem with `fissix` itself. You can choose to suppress `DeprecationWarning` if it becomes too noisy, but it's important to understand its origin.
SystemExit: 2 (or other non-zero exit code) when calling fissix.main.main()
`fissix.main.main()` is designed to mimic command-line execution and calls `sys.exit()` upon completion, including when an error occurs or invalid arguments are passed.
fix
If you need to call `fissix.main.main()` programmatically, wrap the call in a `try...except SystemExit` block to prevent your script from exiting. For purely programmatic code transformations without command-line behavior, it's generally better to use `fissix.refactor.RefactoringTool` directly.
Upgrade
Version history
24.4.24latest on PyPI · released Apr 24, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
fissix — pip install fissix · libregistry