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.
In another case, when we call a function without parentheses, a function reference is sent to the callable rather than executing the function itself. Let’s discuss 3 important concepts:
Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. The following example has a function with one argument (fname). When the function is called, we pass along a first name, which is used inside the function to print the full name:
When you master Python optional arguments, you’ll be able to define functions that are more powerful and more flexible. To get the most out of this tutorial, you’ll need some familiarity with defining functions with required arguments.
Since the merge_string is used without parentheses, the concatenate_string passes the function reference to the callable func rather than executing the merge_string. Hence, we can conclude that when we code sub-function with parentheses in a return statement, the main function executes the sub-function and passes the result to the callable.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With