Neo Py2py3 Converter
Automatically converts legacy Python 2 code to Python 3 with compatibility checks and test generatio
- Rating
- 4.8 (480 reviews)
- Downloads
- 18,754 downloads
- Version
- 1.0.0
Overview
Automatically converts legacy Python 2 code to Python 3 with compatibility checks and test generation.
Complete Documentation
View Source →
py2py3-converter
1. Introduction
py2py3-converter is an OpenClaw skill that automatically converts legacy Python 2 code to modern Python 3 syntax. It handles the most common migration patterns, generates compatibility reports, and creates unit tests for the converted code.
Python 2 reached end-of-life on January 1, 2020, yet many codebases still contain Python 2 code. This skill automates the tedious work of manual migration, reducing human error and accelerating the upgrade process.
2. Core Capabilities
Conversion Logic
The converter handles these Python 2 → 3 transformations:printstatements →print()function callsraw_input()→input()xrange()→range()unicode()→str()basestring→strlongtype →intdict.has_key(k)→k in dictexcept Exception, e→except Exception as eraise ValueError, "msg"→raise ValueError("msg")- Integer division
/awareness __future__import removaliteritems()/itervalues()/iterkeys()→items()/values()/keys()reduce()→functools.reduce()
Compatibility Checking
After conversion, a compatibility report is generated listing:- Warnings for patterns that may need manual review
- Errors for constructs that could not be safely converted
- Informational notes about behavior changes
Test Generation
For each converted file, a companion pytest test file is generated that:- Validates syntax correctness of converted code
- Tests key functions for expected behavior
- Covers detected edge cases
3. Edge Cases Handling
Print Statements
print "hello"→print("hello")print "a", "b"→print("a", "b")print >> sys.stderr, "err"→print("err", file=sys.stderr)print()already valid → left unchanged
String/Bytes Compatibility
u"string"prefix →"string"(default in Python 3)- Warns about
b"bytes"patterns that may need review basestringreferences →str
Import Resolution
from __future__ import print_function→ removed (default in Python 3)import urllib2→import urllib.requestimport ConfigParser→import configparserreduce→ addsfrom functools import reduce
4. CLI Interface
Command Syntax
# Convert a file
node scripts/cli.js convert --input path/to/py2file.py --output path/to/py3file.py
# Convert from stdin
cat py2file.py | node scripts/cli.js convert
# Convert and generate tests
node scripts/cli.js convert --input file.py --output converted.py --generate-tests
# Show compatibility report only
node scripts/cli.js check --input file.py
Exit Codes
0- Conversion successful, no errors1- Conversion completed with warnings2- Conversion failed due to errors
5. Integration
OpenClaw Agent Workflow
Agents invoke the skill via the CLI interface. The standard workflow:- Agent receives Python 2 code from user
- Agent calls
node scripts/cli.js convert --input - Skill returns converted code + compatibility report
- Agent presents results to user
API Contract
Input:{
"code": "print 'hello world'",
"options": {
"generateTests": false,
"keepWarnings": true
}
}
Output:
{
"convertedCode": "print('hello world')",
"issues": [
{
"type": "info",
"line": 1,
"message": "Converted print statement to function call"
}
]
}
Installation
openclaw install neo-py2py3-converter
💻Code Examples
### Command Syntax
# Convert a file
node scripts/cli.js convert --input path/to/py2file.py --output path/to/py3file.py
# Convert from stdin
cat py2file.py | node scripts/cli.js convert
# Convert and generate tests
node scripts/cli.js convert --input file.py --output converted.py --generate-tests
# Show compatibility report only
node scripts/cli.js check --input file.py**Input:**
{
"code": "print 'hello world'",
"options": {
"generateTests": false,
"keepWarnings": true
}
}**Output:**
{
"convertedCode": "print('hello world')",
"issues": [
{
"type": "info",
"line": 1,
"message": "Converted print statement to function call"
}
]
}Tags
Quick Info
Ready to Install?
Get started with this skill in seconds
Related Skills
4claw
4claw — a moderated imageboard for AI agents.
Aap Passport
Agent Attestation Protocol - The Reverse Turing Test.
Adaptive Suite
A continuously adaptive skill suite that empowers Clawdbot.
Adversarial Prompting
Adversarial analysis to critique, fix.