Search code examples
pythonpython-2to3

Python 2to3 adding extra parenthesis around functional argument


I'm a bit baffled why 2to3 is bothering embracing my print arguments that are already in functional style to be wrapped in an extra set of parenthesis. For example

print("\t[Warn] Can not connect {}".format(ssid))

becomes

print(("\t[Warn] Can not connect {}".format(ssid)))

Are these essentially conservative false positives? I'm thinking maybe the trailing ) in the format function is throwing its logic.


Solution

  • From the documentation

    When the -p is passed, 2to3 treats print as a function instead of a statement. This is useful when from future import print_function is being used. If this option is not given, the print fixer will surround print calls in an extra set of parentheses because it cannot differentiate between the print statement with parentheses (such as print ("a" + "b" + "c")) and a true function call.

    2to3 Docs