Search code examples
pythonpython-3.xpython-2to3

python 2to3: How to selectively enable fixers and only do one or two of them?


I am using 2to3 to update some python2 code. Unfortunately there is some fixers I do not like:

  • There are some fixers I do trust (like the print fixer).
  • So I would like to only run one the fixers I trust.

For Python 2to3, how do you disable all fixers and only do one or two fixers? For example if you just want to run print fixer"?


Solution

  • You just have to do:

    2to3 --fix print your_file.py
    
    • I misread the documentation.
    • When you provide no --fix, then all fixers are enabled.
    • If you provide one or more --fix then only those fixers you specify are processed.
    • When you provide --nofix and no --fix, then all fixers are enabled and only the fixers you specify with --nofix are disabled.