Search code examples
pythonpython-2to3

RefactoringTool: ParseError: bad input: type=22, value='='


I'm refactoring some python2 code and changing it to python3 using 2to3 module. I've received following parse error:

RefactoringTool: There was 1 error:
RefactoringTool: Can't parse ./helpers/repo.py: ParseError: bad input: type=22, value='=', context=(' ', (45, 25))

Here is a code that yields the error:

    except ImportError as error_msg:  # pragma: no cover                           
        print(' ',  file = sys.stderr) # this is a line that yields error                                          
        print("Could not locate modifyrepo.py", file=sys.stderr)                
        print("That is odd... should be with createrepo", file=sys.stderr)      
        raise ImportError(error_msg)

I have no clue what could be wrong. Can you please help?


Solution

  • The problem is that the code that you're trying to convert is not valid Python 2 code.

    When running your code using Python 2, you'll get the following error:

      File "repo.py", line 5
        print(' ',  file = sys.stderr) # this is a line that yields error
                         ^
    SyntaxError: invalid syntax
    

    It seems like this code already is Python 3 code. Using Python 3 your code does not yield a SyntaxError.