Python2 brackets for print statements (C0325)
Hi all, I wanted to canvas your opinion about something. Currently, if you have a print statement with brackets in Python2, pylint will raise a comment C0325. This is suppressed if "from __future__ import print_statement" is used. My question is whether or not using print statements with parentheses in python2 should result in a warning. This was brought up as a bug for prospector (see here: https://github.com/landscapeio/prospector/issues/11) and I'm not sure what to decide. On the one hand, without the explicit print function import, the parentheses are superfluous. On the other hand, it is a valid way of making code 2 and 3 compatible. My own thoughts are that the correct way of ensuring Python 2 and 3 compatibility is to use the 'from __future__' import, however that's not compatible with 2.5 and lower. Any thoughts or comments here? Cheers, Carl
I think print(arg) with one argument in python2 should be accepted. Assuming one argument, the behavior is the same between versions, making the question all but pointless - but its usefulness for doing single-source is a strong practical argument for allowing it. The problem comes when you use 0 or 2+ arguments - print(arg1, arg2) and so on - since these do generate different behavior between versions. So in an ideal world, when there is no __future__ import, I think I'd flag print(foo, bar) and print() but not print(foo). On Sun, Jan 26, 2014 at 2:41 PM, Carl Crowder <carl.crowder@gmail.com>wrote:
Hi all,
I wanted to canvas your opinion about something.
Currently, if you have a print statement with brackets in Python2, pylint will raise a comment C0325. This is suppressed if "from __future__ import print_statement" is used.
My question is whether or not using print statements with parentheses in python2 should result in a warning. This was brought up as a bug for prospector (see here: https://github.com/landscapeio/prospector/issues/11) and I'm not sure what to decide. On the one hand, without the explicit print function import, the parentheses are superfluous. On the other hand, it is a valid way of making code 2 and 3 compatible.
My own thoughts are that the correct way of ensuring Python 2 and 3 compatibility is to use the 'from __future__' import, however that's not compatible with 2.5 and lower.
Any thoughts or comments here?
Cheers, Carl _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
participants (2)
-
Carl Crowder
-
Sasha Hart